feat(bump): added strict mode, doesn't build in dist, should be resolved

This commit is contained in:
svetlanaMuravlova
2021-08-17 16:49:19 +03:00
parent 16078f57c3
commit 69cd64dc28
15 changed files with 122 additions and 84 deletions

View File

@@ -10,13 +10,16 @@
"architect": { "architect": {
"build": { "build": {
"builder": "@angular-devkit/build-ng-packagr:build", "builder": "@angular-devkit/build-ng-packagr:build",
"outputs": [
"./dist/ng2-file-upload"
],
"options": { "options": {
"tsConfig": "src/tsconfig.json", "tsConfig": "src/tsconfig.lib.json",
"project": "src/ng-package.json" "project": "src/ng-package.json"
}, },
"configurations": { "configurations": {
"production": { "production": {
"tsConfig": "src/tsconfig.prod.json" "tsConfig": "src/tsconfig.lib.prod.json"
} }
} }
} }

View File

@@ -12,7 +12,7 @@
<link rel="author" href="https://github.com/valor-software/ng2-file-upload/graphs/contributors"> <link rel="author" href="https://github.com/valor-software/ng2-file-upload/graphs/contributors">
<!--link to bootstrap.css--> <!--link to bootstrap.css-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/style.css"> <link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/css/prettify-angulario.css"> <link rel="stylesheet" href="assets/css/prettify-angulario.css">
<style media="screen"> <style media="screen">

View File

@@ -21,5 +21,10 @@
], ],
"exclude": [ "exclude": [
"**/*.spec.ts" "**/*.spec.ts"
] ],
"paths": {
"@ng2-file-upload": [
"../../dist/ng2-file-upload/index.ts"
]
}
} }

View File

@@ -104,7 +104,7 @@
"tslint": "^6.1.0", "tslint": "^6.1.0",
"tslint-config-valorsoft": "^2.2.1", "tslint-config-valorsoft": "^2.2.1",
"typedoc": "0.20.36", "typedoc": "0.20.36",
"typescript": "~4.1.5", "typescript": "4.1.5",
"wallaby-webpack": "^3.9.16", "wallaby-webpack": "^3.9.16",
"webdriver-manager": "12.1.8", "webdriver-manager": "12.1.8",
"zone.js": "~0.11.3" "zone.js": "~0.11.3"

View File

@@ -1,21 +1,5 @@
// This file includes polyfills needed by Angular 2 and is loaded before // This file includes polyfills needed by Angular 2 and is loaded before
// the app. You can add your own extra polyfills to this file. // the app. You can add your own extra polyfills to this file.
import 'ts-helpers'; import 'ts-helpers';
import 'core-js/es/symbol';
import 'core-js/es/object';
import 'core-js/es/function';
import 'core-js/es/parse-int';
import 'core-js/es/parse-float';
import 'core-js/es/number';
import 'core-js/es/math';
import 'core-js/es/string';
import 'core-js/es/date';
import 'core-js/es/array';
import 'core-js/es/regexp';
import 'core-js/es/map';
import 'core-js/es/set';
import 'core-js/es/reflect';
import 'core-js/es/reflect';
import 'zone.js/dist/zone'; import 'zone.js/dist/zone';
import 'classlist-polyfill'; import 'classlist-polyfill';

View File

@@ -4,7 +4,7 @@ import { FileUploader, FileUploaderOptions } from './file-uploader.class';
@Directive({ selector: '[ng2FileDrop]' }) @Directive({ selector: '[ng2FileDrop]' })
export class FileDropDirective { export class FileDropDirective {
@Input() public uploader: FileUploader; @Input() public uploader?: FileUploader;
@Output() public fileOver: EventEmitter<any> = new EventEmitter(); @Output() public fileOver: EventEmitter<any> = new EventEmitter();
@Output() public onFileDrop: EventEmitter<File[]> = new EventEmitter<File[]>(); @Output() public onFileDrop: EventEmitter<File[]> = new EventEmitter<File[]>();
@@ -14,8 +14,8 @@ export class FileDropDirective {
this.element = element; this.element = element;
} }
public getOptions(): FileUploaderOptions { public getOptions(): FileUploaderOptions | void {
return this.uploader.options; return this.uploader?.options;
} }
public getFilters(): any { public getFilters(): any {
@@ -32,7 +32,9 @@ export class FileDropDirective {
let options = this.getOptions(); let options = this.getOptions();
let filters = this.getFilters(); let filters = this.getFilters();
this._preventAndStop(event); this._preventAndStop(event);
this.uploader.addToQueue(transfer.files, options, filters); if (options) {
this.uploader?.addToQueue(transfer.files, options, filters);
}
this.fileOver.emit(false); this.fileOver.emit(false);
this.onFileDrop.emit(transfer.files); this.onFileDrop.emit(transfer.files);
} }

View File

@@ -4,9 +4,9 @@ import { FileUploader, ParsedResponseHeaders, FileUploaderOptions } from './file
export class FileItem { export class FileItem {
public file: FileLikeObject; public file: FileLikeObject;
public _file: File; public _file: File;
public alias: string; public alias?: string;
public url: string = '/'; public url? = '/';
public method: string; public method?: string;
public headers: any = []; public headers: any = [];
public withCredentials: boolean = true; public withCredentials: boolean = true;
public formData: any = []; public formData: any = [];
@@ -17,8 +17,8 @@ export class FileItem {
public isCancel: boolean = false; public isCancel: boolean = false;
public isError: boolean = false; public isError: boolean = false;
public progress: number = 0; public progress: number = 0;
public index: number = void 0; public index?: number;
public _xhr: XMLHttpRequest; public _xhr?: XMLHttpRequest;
public _form: any; public _form: any;
protected uploader: FileUploader; protected uploader: FileUploader;
@@ -111,7 +111,7 @@ export class FileItem {
this.isCancel = false; this.isCancel = false;
this.isError = false; this.isError = false;
this.progress = 100; this.progress = 100;
this.index = void 0; this.index = undefined;
this.onSuccess(response, status, headers); this.onSuccess(response, status, headers);
} }
@@ -123,7 +123,7 @@ export class FileItem {
this.isCancel = false; this.isCancel = false;
this.isError = true; this.isError = true;
this.progress = 0; this.progress = 0;
this.index = void 0; this.index = undefined;
this.onError(response, status, headers); this.onError(response, status, headers);
} }
@@ -135,7 +135,7 @@ export class FileItem {
this.isCancel = true; this.isCancel = true;
this.isError = false; this.isError = false;
this.progress = 0; this.progress = 0;
this.index = void 0; this.index = undefined;
this.onCancel(response, status, headers); this.onCancel(response, status, headers);
} }

View File

@@ -5,8 +5,8 @@ function isElement(node: any): boolean {
export class FileLikeObject { export class FileLikeObject {
public lastModifiedDate: any; public lastModifiedDate: any;
public size: any; public size: any;
public type: string; public type?: string;
public name: string; public name?: string;
public rawFile: string; public rawFile: string;
public constructor(fileOrInput: any) { public constructor(fileOrInput: any) {

View File

@@ -1,10 +1,10 @@
import { Directive, EventEmitter, ElementRef, Input, HostListener, Output } from '@angular/core'; import { Directive, EventEmitter, ElementRef, Input, HostListener, Output } from '@angular/core';
import { FileUploader } from './file-uploader.class'; import {FileUploader, FileUploaderOptions} from './file-uploader.class';
@Directive({ selector: '[ng2FileSelect]' }) @Directive({ selector: '[ng2FileSelect]' })
export class FileSelectDirective { export class FileSelectDirective {
@Input() public uploader: FileUploader; @Input() public uploader?: FileUploader;
@Output() public onFileSelected: EventEmitter<File[]> = new EventEmitter<File[]>(); @Output() public onFileSelected: EventEmitter<File[]> = new EventEmitter<File[]>();
protected element: ElementRef; protected element: ElementRef;
@@ -13,8 +13,8 @@ export class FileSelectDirective {
this.element = element; this.element = element;
} }
public getOptions(): any { public getOptions(): FileUploaderOptions | void {
return this.uploader.options; return this.uploader?.options;
} }
public getFilters(): any { public getFilters(): any {
@@ -30,10 +30,11 @@ export class FileSelectDirective {
let files = this.element.nativeElement.files; let files = this.element.nativeElement.files;
let options = this.getOptions(); let options = this.getOptions();
let filters = this.getFilters(); let filters = this.getFilters();
if (options) {
this.uploader?.addToQueue(files, options, filters);
}
this.uploader.addToQueue(files, options, filters);
this.onFileSelected.emit(files); this.onFileSelected.emit(files);
if (this.isEmptyAfterSelection()) { if (this.isEmptyAfterSelection()) {
this.element.nativeElement.value = ''; this.element.nativeElement.value = '';
} }

View File

@@ -62,26 +62,26 @@ export class FileType {
public static getMimeClass(file: FileLikeObject): string { public static getMimeClass(file: FileLikeObject): string {
let mimeClass = 'application'; let mimeClass = 'application';
if (this.mime_psd.indexOf(file.type) !== -1) { if (file?.type && this.mime_psd.indexOf(file.type) !== -1) {
mimeClass = 'image'; mimeClass = 'image';
} else if (file.type.match('image.*')) { } else if (file?.type?.match('image.*')) {
mimeClass = 'image'; mimeClass = 'image';
} else if (file.type.match('video.*')) { } else if (file?.type?.match('video.*')) {
mimeClass = 'video'; mimeClass = 'video';
} else if (file.type.match('audio.*')) { } else if (file?.type?.match('audio.*')) {
mimeClass = 'audio'; mimeClass = 'audio';
} else if (file.type === 'application/pdf') { } else if (file?.type === 'application/pdf') {
mimeClass = 'pdf'; mimeClass = 'pdf';
} else if (this.mime_compress.indexOf(file.type) !== -1) { } else if (file?.type && this.mime_compress.indexOf(file.type) !== -1) {
mimeClass = 'compress'; mimeClass = 'compress';
} else if (this.mime_doc.indexOf(file.type) !== -1) { } else if (file?.type && this.mime_doc.indexOf(file.type) !== -1) {
mimeClass = 'doc'; mimeClass = 'doc';
} else if (this.mime_xsl.indexOf(file.type) !== -1) { } else if (file?.type && this.mime_xsl.indexOf(file.type) !== -1) {
mimeClass = 'xls'; mimeClass = 'xls';
} else if (this.mime_ppt.indexOf(file.type) !== -1) { } else if (file?.type && this.mime_ppt.indexOf(file.type) !== -1) {
mimeClass = 'ppt'; mimeClass = 'ppt';
} }
if (mimeClass === 'application') { if (mimeClass === 'application' && file?.name) {
mimeClass = this.fileTypeDetection(file.name); mimeClass = this.fileTypeDetection(file.name);
} }

View File

@@ -16,7 +16,7 @@ export type ParsedResponseHeaders = { [ headerFieldName: string ]: string };
export type FilterFunction = { export type FilterFunction = {
name: string, name: string,
fn: (item?: FileLikeObject, options?: FileUploaderOptions) => boolean fn: (item: FileLikeObject, options?: FileUploaderOptions) => boolean
}; };
export interface FileUploaderOptions { export interface FileUploaderOptions {
@@ -43,13 +43,13 @@ export interface FileUploaderOptions {
export class FileUploader { export class FileUploader {
public authToken: string; public authToken?: string;
public isUploading: boolean = false; public isUploading: boolean = false;
public queue: FileItem[] = []; public queue: FileItem[] = [];
public progress: number = 0; public progress: number = 0;
public _nextIndex: number = 0; public _nextIndex: number = 0;
public autoUpload: any; public autoUpload: any;
public authTokenHeader: string; public authTokenHeader?: string;
public response: EventEmitter<any>; public response: EventEmitter<any>;
public options: FileUploaderOptions = { public options: FileUploaderOptions = {
@@ -62,7 +62,7 @@ export class FileUploader {
formatDataFunctionIsAsync: false formatDataFunctionIsAsync: false
}; };
protected _failFilterIndex: number; protected _failFilterIndex?: number;
public constructor(options: FileUploaderOptions) { public constructor(options: FileUploaderOptions) {
this.setOptions(options); this.setOptions(options);
@@ -75,18 +75,18 @@ export class FileUploader {
this.authToken = this.options.authToken; this.authToken = this.options.authToken;
this.authTokenHeader = this.options.authTokenHeader || 'Authorization'; this.authTokenHeader = this.options.authTokenHeader || 'Authorization';
this.autoUpload = this.options.autoUpload; this.autoUpload = this.options.autoUpload;
this.options.filters.unshift({ name: 'queueLimit', fn: this._queueLimitFilter }); this.options.filters?.unshift({ name: 'queueLimit', fn: this._queueLimitFilter });
if (this.options.maxFileSize) { if (this.options.maxFileSize && this.options.filters) {
this.options.filters.unshift({ name: 'fileSize', fn: this._fileSizeFilter }); this.options.filters.unshift({ name: 'fileSize', fn: this._fileSizeFilter });
} }
if (this.options.allowedFileType) { if (this.options.allowedFileType) {
this.options.filters.unshift({ name: 'fileType', fn: this._fileTypeFilter }); this.options.filters?.unshift({ name: 'fileType', fn: this._fileTypeFilter });
} }
if (this.options.allowedMimeType) { if (this.options.allowedMimeType) {
this.options.filters.unshift({ name: 'mimeType', fn: this._mimeTypeFilter }); this.options.filters?.unshift({ name: 'mimeType', fn: this._mimeTypeFilter });
} }
for (let i = 0; i < this.queue.length; i++) { for (let i = 0; i < this.queue.length; i++) {
@@ -114,8 +114,10 @@ export class FileUploader {
this.queue.push(fileItem); this.queue.push(fileItem);
this._onAfterAddingFile(fileItem); this._onAfterAddingFile(fileItem);
} else { } else {
let filter = arrayOfFilters[ this._failFilterIndex ]; if (this._failFilterIndex) {
this._onWhenAddingFileFailed(temp, filter, options); let filter = arrayOfFilters[ this._failFilterIndex ];
this._onWhenAddingFileFailed(temp, filter, options);
}
} }
}); });
if (this.queue.length !== count) { if (this.queue.length !== count) {
@@ -255,7 +257,7 @@ export class FileUploader {
} }
public _mimeTypeFilter(item: FileLikeObject): boolean { public _mimeTypeFilter(item: FileLikeObject): boolean {
return !(this.options.allowedMimeType && this.options.allowedMimeType.indexOf(item.type) === -1); return !(item?.type && this.options.allowedMimeType && this.options.allowedMimeType?.indexOf(item.type) === -1);
} }
public _fileSizeFilter(item: FileLikeObject): boolean { public _fileSizeFilter(item: FileLikeObject): boolean {
@@ -307,29 +309,33 @@ export class FileUploader {
if (!this.options.disableMultipart) { if (!this.options.disableMultipart) {
sendable = new FormData(); sendable = new FormData();
this._onBuildItemForm(item, sendable); this._onBuildItemForm(item, sendable);
let appendFile;
const appendFile = () => sendable.append(item.alias, item._file, item.file.name); if (item.alias && item._file && item.file.name) {
if (!this.options.parametersBeforeFiles) { appendFile = () => sendable.append(item.alias, item._file, item.file.name);
appendFile(); if (!this.options.parametersBeforeFiles) {
appendFile();
}
} }
// For AWS, Additional Parameters must come BEFORE Files // For AWS, Additional Parameters must come BEFORE Files
if (this.options.additionalParameter !== undefined) { if (this.options.additionalParameter !== undefined) {
Object.keys(this.options.additionalParameter).forEach((key: string) => { Object.keys(this.options.additionalParameter).forEach((key: string) => {
let paramVal = this.options.additionalParameter[ key ]; let paramVal = this.options.additionalParameter?.[ key ];
// Allow an additional parameter to include the filename // Allow an additional parameter to include the filename
if (typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0) { if (typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0 && item.file?.name) {
paramVal = paramVal.replace('{{file_name}}', item.file.name); paramVal = paramVal.replace('{{file_name}}', item.file.name);
} }
sendable.append(key, paramVal); sendable.append(key, paramVal);
}); });
} }
if (this.options.parametersBeforeFiles) { if (appendFile && this.options.parametersBeforeFiles) {
appendFile(); appendFile();
} }
} else { } else {
sendable = this.options.formatDataFunction(item); if (this.options.formatDataFunction) {
sendable = this.options.formatDataFunction(item);
}
} }
xhr.upload.onprogress = (event: any) => { xhr.upload.onprogress = (event: any) => {
@@ -356,7 +362,9 @@ export class FileUploader {
this._onCancelItem(item, response, xhr.status, headers); this._onCancelItem(item, response, xhr.status, headers);
this._onCompleteItem(item, response, xhr.status, headers); this._onCompleteItem(item, response, xhr.status, headers);
}; };
xhr.open(item.method, item.url, true); if (item.method && item.url) {
xhr.open(item.method, item.url, true);
}
xhr.withCredentials = item.withCredentials; xhr.withCredentials = item.withCredentials;
if (this.options.headers) { if (this.options.headers) {
for (let header of this.options.headers) { for (let header of this.options.headers) {
@@ -368,7 +376,7 @@ export class FileUploader {
xhr.setRequestHeader(header.name, header.value); xhr.setRequestHeader(header.name, header.value);
} }
} }
if (this.authToken) { if (this.authToken && this.authTokenHeader) {
xhr.setRequestHeader(this.authTokenHeader, this.authToken); xhr.setRequestHeader(this.authTokenHeader, this.authToken);
} }
xhr.onreadystatechange = function () { xhr.onreadystatechange = function () {
@@ -397,19 +405,19 @@ export class FileUploader {
return Math.round(uploaded * ratio + current); return Math.round(uploaded * ratio + current);
} }
protected _getFilters(filters: FilterFunction[] | string): FilterFunction[] { protected _getFilters(filters?: FilterFunction[] | string): FilterFunction[] | [] {
if (!filters) { if (!filters) {
return this.options.filters; return this.options?.filters || [];
} }
if (Array.isArray(filters)) { if (Array.isArray(filters)) {
return filters; return filters;
} }
if (typeof filters === 'string') { if (typeof filters === 'string') {
let names = filters.match(/[^\s,]+/g); let names = filters.match(/[^\s,]+/g);
return this.options.filters return this.options?.filters || []
.filter((filter: any) => names.indexOf(filter.name) !== -1); .filter((filter: any) => names?.indexOf(filter.name) !== -1);
} }
return this.options.filters; return this.options?.filters || [];
} }
protected _render(): any { protected _render(): any {
@@ -423,7 +431,9 @@ export class FileUploader {
protected _isValidFile(file: FileLikeObject, filters: FilterFunction[], options: FileUploaderOptions): boolean { protected _isValidFile(file: FileLikeObject, filters: FilterFunction[], options: FileUploaderOptions): boolean {
this._failFilterIndex = -1; this._failFilterIndex = -1;
return !filters.length ? true : filters.every((filter: FilterFunction) => { return !filters.length ? true : filters.every((filter: FilterFunction) => {
this._failFilterIndex++; if (typeof this._failFilterIndex === 'number') {
this._failFilterIndex++;
}
return filter.fn.call(this, file, options); return filter.fn.call(this, file, options);
}); });
} }

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "../node_modules/ng-packagr/ng-package.schema.json", "$schema": "../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../dist/ng2-file-upload", "dest": "../node_modules/ng2-file-upload",
"lib": { "lib": {
"entryFile": "index.ts" "entryFile": "index.ts"
} }

View File

@@ -1,8 +1,8 @@
{ {
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": ".",
"outDir": "../dist", "outDir": "../dist/ng2-file-upload",
"target": "es5", "target": "es2015",
"module": "esnext", "module": "esnext",
"moduleResolution": "node", "moduleResolution": "node",
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
@@ -15,13 +15,17 @@
"stripInternal": true, "stripInternal": true,
"noUnusedLocals": false, "noUnusedLocals": false,
"noUnusedParameters": false, "noUnusedParameters": false,
"lib": ["dom", "es6"] "lib": ["dom", "es2018"],
"strict": true
}, },
"angularCompilerOptions": { "angularCompilerOptions": {
"annotateForClosureCompiler": true, "annotateForClosureCompiler": true,
"strictMetadataEmit": true, "strictMetadataEmit": true,
"skipTemplateCodegen": true, "skipTemplateCodegen": true,
"flatModuleOutFile": "ng2-file-upload.js", "strictInjectionParameters": true,
"strictTemplates": false,
"fullTemplateTypeCheck": true,
"flatModuleOutFile": "ng2-file-upload.d.ts",
"flatModuleId": "ng2-file-upload" "flatModuleId": "ng2-file-upload"
}, },
"include": [ "include": [
@@ -29,5 +33,13 @@
], ],
"exclude": [ "exclude": [
"**/*.spec.ts" "**/*.spec.ts"
],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.lib.prod.json"
}
] ]
} }

20
src/tsconfig.lib.json Normal file
View File

@@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../dist/ng2-file-upload",
"target": "es2015",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": ["dom", "es2018"]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": [
"**/*.spec.ts"],
"include": ["**/*.ts"]
}

View File

@@ -1,5 +1,6 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.lib.json",
"compilerOptions": { "compilerOptions": {
"declarationMap": false "declarationMap": false
}, },