BREAKING CHANGE(core): switch to esm

This commit is contained in:
Philipp Kunz 2022-06-07 15:43:28 +02:00
parent 38f001ab23
commit 0e22999f69
17 changed files with 2810 additions and 18677 deletions

4
.snyk
View File

@ -1,4 +0,0 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.13.1
ignore: {}
patch: {}

22
LICENSE
View File

@ -1,22 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 Lossless GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,8 +1,4 @@
{
"npmts": {
"mode": "default",
"coverageTreshold": 70
},
"npmdocker": {},
"npmci": {
"npmGlobalTools": [],

21279
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,9 +5,10 @@
"description": "offers smart ways to work with files in nodejs",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild --web)"
"build": "(tsbuild --web --allowimplicitany)"
},
"repository": {
"type": "git",
@ -24,33 +25,31 @@
},
"homepage": "https://gitlab.com/pushrocks/smartfile",
"dependencies": {
"@pushrocks/lik": "^5.0.0",
"@pushrocks/lik": "^6.0.0",
"@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartfile-interfaces": "^1.0.7",
"@pushrocks/smarthash": "^2.1.10",
"@pushrocks/smartjson": "^4.0.6",
"@pushrocks/smartmime": "^1.0.5",
"@pushrocks/smartpath": "^4.0.3",
"@pushrocks/smartpath": "^5.0.5",
"@pushrocks/smartpromise": "^3.1.6",
"@pushrocks/smartrequest": "^1.1.52",
"@pushrocks/smartrequest": "^1.1.56",
"@pushrocks/smartstream": "^2.0.1",
"@pushrocks/streamfunction": "^4.0.4",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/js-yaml": "^4.0.5",
"fs-extra": "^10.0.0",
"glob": "^7.2.0",
"fs-extra": "^10.1.0",
"glob": "^8.0.3",
"js-yaml": "^4.1.0"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.28",
"@gitzone/tsrun": "^1.2.18",
"@gitzone/tstest": "^1.0.60",
"@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^16.11.11",
"gulp-function": "^2.2.14",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
"@gitzone/tsbuild": "^2.1.63",
"@gitzone/tsrun": "^1.2.35",
"@gitzone/tstest": "^1.0.71",
"@pushrocks/tapbundle": "^5.0.3",
"@types/node": "^17.0.40",
"gulp-function": "^2.2.14"
},
"files": [
"ts/**/*",

View File

@ -1,4 +1,4 @@
import * as smartfile from '../ts/index';
import * as smartfile from '../ts/index.js';
import * as path from 'path';
import { expect, tap } from '@pushrocks/tapbundle';
@ -9,47 +9,47 @@ import { expect, tap } from '@pushrocks/tapbundle';
tap.test('.fs.fileExistsSync -> should return an accurate boolean', async () => {
// tslint:disable-next-line: no-unused-expression
expect(smartfile.fs.fileExistsSync('./test/testassets/mytest.json')).to.be.true;
expect(smartfile.fs.fileExistsSync('./test/testassets/mytest.json')).toBeTrue();
// tslint:disable-next-line: no-unused-expression
expect(smartfile.fs.fileExistsSync('./test/testassets/notthere.json')).be.false;
expect(smartfile.fs.fileExistsSync('./test/testassets/notthere.json')).toBeFalse();
});
tap.test('.fs.fileExists -> should resolve or reject a promise', async () => {
expect(smartfile.fs.fileExists('./test/testassets/mytest.json')).to.be.instanceof(Promise);
expect(smartfile.fs.fileExists('./test/testassets/mytest.json')).toBeInstanceOf(Promise);
await smartfile.fs.fileExists('./test/testassets/mytest.json');
await smartfile.fs.fileExists('./test/testassets/notthere.json').catch((err) => {
return expect(err.message).to.equal(
return expect(err.message).toEqual(
"ENOENT: no such file or directory, access './test/testassets/notthere.json'"
);
});
});
tap.test('.fs.listFoldersSync() -> should get the file type from a string', async () => {
expect(smartfile.fs.listFoldersSync('./test/testassets/')).to.include('testfolder');
expect(smartfile.fs.listFoldersSync('./test/testassets/')).to.not.include('notExistentFolder');
expect(smartfile.fs.listFoldersSync('./test/testassets/')).toContain('testfolder');
expect(smartfile.fs.listFoldersSync('./test/testassets/')).not.toContain('notExistentFolder');
});
tap.test('.fs.listFolders() -> should get the file type from a string', async () => {
const folderArrayArg = await smartfile.fs.listFolders('./test/testassets/');
expect(folderArrayArg).to.include('testfolder');
expect(folderArrayArg).to.not.include('notExistentFolder');
expect(folderArrayArg).toContain('testfolder');
expect(folderArrayArg).not.toContain('notExistentFolder');
});
tap.test('.fs.listFilesSync() -> should get the file type from a string', async () => {
expect(smartfile.fs.listFilesSync('./test/testassets/')).to.include('mytest.json');
expect(smartfile.fs.listFilesSync('./test/testassets/')).to.not.include('notExistentFile');
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytest\.json/)).to.include(
expect(smartfile.fs.listFilesSync('./test/testassets/')).toContain('mytest.json');
expect(smartfile.fs.listFilesSync('./test/testassets/')).not.toContain('notExistentFile');
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytest\.json/)).toContain(
'mytest.json'
);
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytests.json/)).to.not.include(
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytests.json/)).not.toContain(
'mytest.json'
);
});
tap.test('.fs.listFiles() -> should get the file type from a string', async () => {
const folderArrayArg = await smartfile.fs.listFiles('./test/testassets/');
expect(folderArrayArg).to.include('mytest.json');
expect(folderArrayArg).to.not.include('notExistentFile');
expect(folderArrayArg).toContain('mytest.json');
expect(folderArrayArg).not.toContain('notExistentFile');
});
tap.test('.fs.listFileTree() -> should get a file tree', async () => {
@ -57,8 +57,8 @@ tap.test('.fs.listFileTree() -> should get a file tree', async () => {
path.resolve('./test/testassets/'),
'**/*.txt'
);
expect(folderArrayArg).to.include('testfolder/testfile1.txt');
expect(folderArrayArg).to.not.include('mytest.json');
expect(folderArrayArg).toContain('testfolder/testfile1.txt');
expect(folderArrayArg).not.toContain('mytest.json');
});
tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async () => {
@ -66,8 +66,8 @@ tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async
path.resolve('./test/testassets/'),
'**/*.txt'
);
expect(fileArrayArg[0]).to.be.instanceof(smartfile.Smartfile);
expect(fileArrayArg[0].contents.toString()).to.equal(fileArrayArg[0].contentBuffer.toString());
expect(fileArrayArg[0]).toBeInstanceOf(smartfile.Smartfile);
expect(fileArrayArg[0].contents.toString()).toEqual(fileArrayArg[0].contentBuffer.toString());
});
tap.test('.fs.copy() -> should copy a directory', async () => {
@ -93,15 +93,15 @@ tap.test('.fs.remove -> should remove single files', async () => {
tap.test('.fs.removeSync -> should remove single files synchronouly', async () => {
smartfile.fs.removeSync('./test/testassets/temp/testfile1.txt');
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false;
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
});
tap.test('.fs.removeMany -> should remove and array of files', async () => {
smartfile.fs
.removeMany(['./test/testassets/temp/testfile1.txt', './test/testassets/temp/testfile2.txt'])
.then(() => {
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false;
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).to.be.false;
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).toBeFalse();
});
});
@ -110,14 +110,14 @@ tap.test('.fs.removeManySync -> should remove and array of single files synchron
'./test/testassets/temp/testfile1.txt',
'./test/testassets/temp/testfile2.txt',
]);
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false;
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).to.be.false;
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).toBeFalse();
});
tap.test('.fs.toObjectSync() -> should read an ' + '.yaml' + ' file to an object', async () => {
tap.test('.fs.toObjectSync() -> should read an .yaml file to an object', async () => {
const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.yaml');
expect(testData).to.include({ key1: 'this works' });
expect(testData).to.include({ key2: 'this works too' });
expect(testData.key1).toEqual('this works');
expect(testData.key2).toEqual('this works too');
});
tap.test(
'.fs.toObjectSync() -> should state unknown file type for unknown file types',
@ -126,14 +126,14 @@ tap.test(
}
);
tap.test('.fs.toObjectSync() -> should read an ' + '.json' + ' file to an object', async () => {
tap.test('.fs.toObjectSync() -> should read an .json file to an object', async () => {
const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.json');
expect(testData).to.include({ key1: 'this works' });
expect(testData).to.include({ key2: 'this works too' });
expect(testData.key1).toEqual('this works');
expect(testData.key2).toEqual('this works too');
});
tap.test('.fs.toStringSync() -> should read a file to a string', async () => {
expect(smartfile.fs.toStringSync('./test/testassets/mytest.txt')).to.equal(
expect(smartfile.fs.toStringSync('./test/testassets/mytest.txt')).toEqual(
'Some TestString &&%$'
);
});
@ -143,7 +143,7 @@ tap.test('.fs.toStringSync() -> should read a file to a string', async () => {
// ---------------------------
tap.test('.interpreter.filetype() -> should get the file type from a string', async () => {
expect(smartfile.interpreter.filetype('./somefolder/data.json')).equal('json');
expect(smartfile.interpreter.filetype('./somefolder/data.json')).toEqual('json');
});
// ---------------------------
@ -179,14 +179,14 @@ tap.test('.Smartfile -> should produce vinyl compatible files', async () => {
'./test/testassets/testfolder/**/*'
);
const localSmartfile = smartfileArray[0];
expect(localSmartfile).to.be.instanceof(smartfile.Smartfile);
expect(localSmartfile.contents).to.be.instanceof(Buffer);
expect(localSmartfile).toBeInstanceOf(smartfile.Smartfile);
expect(localSmartfile.contents).toBeInstanceOf(Buffer);
// tslint:disable-next-line:no-unused-expression
expect(localSmartfile.isBuffer()).to.be.true;
expect(localSmartfile.isBuffer()).toBeTrue();
// tslint:disable-next-line:no-unused-expression
expect(localSmartfile.isDirectory()).to.be.false;
expect(localSmartfile.isDirectory()).toBeFalse();
// tslint:disable-next-line:no-unused-expression
expect(localSmartfile.isNull()).to.be.false;
expect(localSmartfile.isNull()).toBeFalse();
});
tap.test('should output a smartfile array to disk', async () => {
@ -210,7 +210,7 @@ tap.test('should create, store and retrieve valid smartfiles', async () => {
smartfileInstance.write();
const smartfileInstance2 = await smartfile.Smartfile.fromFilePath(filePath);
const retrievedString = smartfileInstance.contents.toString();
expect(retrievedString).to.equal(fileString);
expect(retrievedString).toEqual(fileString);
});
tap.test('should wait for file to be ready', async () => {

View File

@ -1,10 +1,10 @@
import { tap, expect } from '@pushrocks/tapbundle';
import * as smartfile from '../ts';
import * as smartfile from '../ts/index.js';
tap.test('should create a virtualdirectory', async () => {
const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath('./test/testassets/testfolder');
expect(virtualDir.smartfileArray.length).to.equal(4);
expect(virtualDir.smartfileArray.length).toEqual(4);
});
tap.test('should write to a directory', async () => {

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@pushrocks/smartfile',
version: '9.0.7',
version: '10.0.0',
description: 'offers smart ways to work with files in nodejs'
}

View File

@ -1,11 +1,11 @@
import * as plugins from './smartfile.plugins';
import * as fsMod from './smartfile.fs';
import * as fsStreamMod from './smartfile.fsstream';
import * as interpreterMod from './smartfile.interpreter';
import * as memoryMod from './smartfile.memory';
import * as plugins from './smartfile.plugins.js';
import * as fsMod from './smartfile.fs.js';
import * as fsStreamMod from './smartfile.fsstream.js';
import * as interpreterMod from './smartfile.interpreter.js';
import * as memoryMod from './smartfile.memory.js';
export { Smartfile, ISmartfileConstructorOptions } from './smartfile.classes.smartfile';
export { VirtualDirectory } from './smartfile.classes.virtualdirectory';
export * from './smartfile.classes.smartfile.js';
export * from './smartfile.classes.virtualdirectory.js';
export const fs = fsMod;
export const fsStream = fsStreamMod;

View File

@ -1,6 +1,6 @@
import * as plugins from './smartfile.plugins';
import * as fs from './smartfile.fs';
import * as memory from './smartfile.memory';
import * as plugins from './smartfile.plugins.js';
import * as fs from './smartfile.fs.js';
import * as memory from './smartfile.memory.js';
export interface ISmartfileConstructorOptions {
path: string;
@ -158,7 +158,7 @@ export class Smartfile extends plugins.smartjson.Smartjson {
* @returns
*/
public async writeToDir(dirPathArg: string) {
dirPathArg = plugins.smartpath.transform.toAbsolute(dirPathArg);
dirPathArg = plugins.smartpath.transform.toAbsolute(dirPathArg) as string;
const filePath = plugins.path.join(dirPathArg, this.path);
await memory.toFs(this.contentBuffer, filePath);
return filePath;

View File

@ -1,6 +1,6 @@
import { Smartfile } from './smartfile.classes.smartfile';
import * as plugins from './smartfile.plugins';
import * as fs from './smartfile.fs';
import { Smartfile } from './smartfile.classes.smartfile.js';
import * as plugins from './smartfile.plugins.js';
import * as fs from './smartfile.fs.js';
/**
* a virtual directory exposes a fs api

View File

@ -1,9 +1,9 @@
import * as plugins from './smartfile.plugins';
import * as interpreter from './smartfile.interpreter';
import * as plugins from './smartfile.plugins.js';
import * as interpreter from './smartfile.interpreter.js';
import { Smartfile } from './smartfile.classes.smartfile';
import { Smartfile } from './smartfile.classes.smartfile.js';
import * as memory from './smartfile.memory';
import * as memory from './smartfile.memory.js';
/*===============================================================
============================ Checks =============================
===============================================================*/
@ -231,7 +231,7 @@ export const fileTreeToObject = async (dirPathArg: string, miniMatchFilter: stri
if (plugins.path.isAbsolute(miniMatchFilter)) {
dirPath = '/';
} else {
dirPath = plugins.smartpath.transform.toAbsolute(dirPathArg);
dirPath = plugins.smartpath.transform.toAbsolute(dirPathArg) as string;
}
const fileTree = await listFileTree(dirPath, miniMatchFilter);

View File

@ -1,7 +1,7 @@
/*
This file contains logic for streaming things from and to the filesystem
*/
import * as plugins from './smartfile.plugins';
import * as plugins from './smartfile.plugins.js';
export const createReadStream = (pathArg: string) => {
return plugins.fs.createReadStream(pathArg);

View File

@ -1,4 +1,4 @@
import * as plugins from './smartfile.plugins';
import * as plugins from './smartfile.plugins.js';
export let filetype = (pathArg: string): string => {
const extName = plugins.path.extname(pathArg);

View File

@ -1,7 +1,7 @@
import * as plugins from './smartfile.plugins';
import { Smartfile } from './smartfile.classes.smartfile';
import * as smartfileFs from './smartfile.fs';
import * as interpreter from './smartfile.interpreter';
import * as plugins from './smartfile.plugins.js';
import { Smartfile } from './smartfile.classes.smartfile.js';
import * as smartfileFs from './smartfile.fs.js';
import * as interpreter from './smartfile.interpreter.js';
/**
* converts file to Object

View File

@ -30,7 +30,7 @@ export {
};
// third party scope
import * as fsExtra from 'fs-extra';
import fsExtra from 'fs-extra';
import glob from 'glob';
import yaml from 'js-yaml';

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}