Skip to content

Commit c5950c4

Browse files
committed
refactor: Migrate to ES Modules and update build and test configurations
1 parent 09a4cb0 commit c5950c4

File tree

10 files changed

+101
-2867
lines changed

10 files changed

+101
-2867
lines changed

.jshintrc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"node": true,
33
"browser": true,
4-
"esnext": true,
4+
"esversion": 11,
5+
"module": true,
56
"bitwise": true,
67
"camelcase": true,
78
"curly": true,
@@ -31,11 +32,11 @@
3132
"loopfunc": true,
3233
"sub": true,
3334
"globals": {
34-
"angular" : false,
35+
"angular": false,
3536
"jasmine": false,
3637
"inject": false,
3738
"alert": false,
38-
"_" : true,
39+
"_": true,
3940
"xit": false,
4041
"xdescribe": false,
4142
"it": false,
@@ -47,5 +48,5 @@
4748
"before": false,
4849
"after": false,
4950
"expect": false
50-
}
51+
}
5152
}

Gruntfile.js renamed to Gruntfile.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module.exports = function (grunt) {
5555
reporter: 'dot',
5656
'forbid-only': true,
5757
},
58-
all : {
58+
all: {
5959
src: [
6060
'test/api/**/*.js'
6161
]
@@ -64,7 +64,7 @@ module.exports = function (grunt) {
6464

6565
karma: {
6666
unit: {
67-
configFile: 'test/karma.conf.js',
67+
configFile: 'test/karma.conf.cjs',
6868
singleRun: true
6969
}
7070
},

lib/fng-jq-upload.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"use strict";
21
var __extends = (this && this.__extends) || (function () {
32
var extendStatics = function (d, b) {
43
extendStatics = Object.setPrototypeOf ||
@@ -24,8 +23,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2423
});
2524
};
2625
var __generator = (this && this.__generator) || function (thisArg, body) {
27-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
27+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2928
function verb(n) { return function (v) { return step([n, v]); }; }
3029
function step(op) {
3130
if (f) throw new TypeError("Generator is already executing.");
@@ -51,27 +50,25 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
5150
}
5251
};
5352
var _a;
54-
Object.defineProperty(exports, "__esModule", { value: true });
55-
exports.controller = exports.createThumbnailStreamIfNeeded = exports.TooLargeError = exports.TOO_LARGE_FLAG = exports.FileSchema = void 0;
56-
var mongoose = require("mongoose");
57-
var path = require("path");
58-
var busboy = require("busboy");
59-
var ims = require("imagemagick-stream");
53+
import mongoose from "mongoose";
54+
import path from "path";
55+
import busboy from "busboy";
56+
import ims from "imagemagick-stream";
6057
// the numeric values are written to the document property that stores the reference to the file (which
6158
// will be of type FileSchemaObj, using schema FileSchema - see below).
6259
var StoreInMongoDB = 1;
63-
exports.FileSchema = {
60+
export var FileSchema = {
6461
filename: String,
6562
size: Number,
66-
location: Number,
63+
location: Number, // valueof StoredFileLocation
6764
thumbnailId: {
6865
type: mongoose.Schema.Types.ObjectId,
6966
form: {
7067
hidden: true, // needed to prevent fng from complaining about "No supported select lookup type..."
7168
},
7269
},
7370
};
74-
exports.TOO_LARGE_FLAG = "__tooLarge";
71+
export var TOO_LARGE_FLAG = "__tooLarge";
7572
var TooLargeError = /** @class */ (function (_super) {
7673
__extends(TooLargeError, _super);
7774
function TooLargeError() {
@@ -82,8 +79,8 @@ var TooLargeError = /** @class */ (function (_super) {
8279
}
8380
return TooLargeError;
8481
}(Error));
85-
exports.TooLargeError = TooLargeError;
86-
_a = exports.TOO_LARGE_FLAG;
82+
export { TooLargeError };
83+
_a = TOO_LARGE_FLAG;
8784
function storeOneFileInMongoDB(gridFSBucket, file, options, callback) {
8885
var internalOptions = {};
8986
if (options.metadata) {
@@ -102,7 +99,7 @@ function storeOneFileInMongoDB(gridFSBucket, file, options, callback) {
10299
});
103100
file.pipe(stream);
104101
}
105-
function createThumbnailStreamIfNeeded(opts, filename) {
102+
export function createThumbnailStreamIfNeeded(opts, filename) {
106103
if (!opts.required) {
107104
return;
108105
}
@@ -133,7 +130,6 @@ function createThumbnailStreamIfNeeded(opts, filename) {
133130
// unsharp can improve the image quality after the resize. See https://legacy.imagemagick.org/Usage/thumbnails/#height.
134131
return ims().thumbnail(size).autoOrient().op("unsharp", "0x.5").inputFormat(type).outputFormat(type);
135132
}
136-
exports.createThumbnailStreamIfNeeded = createThumbnailStreamIfNeeded;
137133
function storeInMongoDB(fng, resource, file, filename, schemaThumbnailOpts) {
138134
var mongo = fng.mongoose.mongo;
139135
var bucketName = resource.model.collection.name;
@@ -176,7 +172,7 @@ function storeInMongoDB(fng, resource, file, filename, schemaThumbnailOpts) {
176172
});
177173
});
178174
}
179-
function controller(fng, processArgs, options) {
175+
export function controller(fng, processArgs, options) {
180176
var modifiedFngOpts = Object.assign({}, fng.options);
181177
if (options.inhibitAuthentication) {
182178
delete modifiedFngOpts.authentication;
@@ -228,7 +224,7 @@ function controller(fng, processArgs, options) {
228224
// handler, below, because otherwise the error will leak out to the "next" handler and get reported to Sentry
229225
.catch(function (e) {
230226
// can't use instanceof here (think the compiler options need to be more up-to-date to allow that)
231-
if (exports.TOO_LARGE_FLAG in e) {
227+
if (TOO_LARGE_FLAG in e) {
232228
var units = "byte";
233229
var value = storageLimits.maxFileSize;
234230
if (value % 1024 === 0) {
@@ -350,6 +346,10 @@ function controller(fng, processArgs, options) {
350346
]));
351347
// the route used when deleting a file (when clicking on the trashcan icon that is provided alongside the thumbnail)
352348
fng.app.delete.apply(fng.app, processArgs(modifiedFngOpts, [
349+
// if you think you want to change this route (in particular, changing the name of the :id param),
350+
// ensure that the host app does not (through the modifiedFngArgs) inject some additional handlers
351+
// (perhaps related to permissions) which expect certain params to exist.
352+
// Plait developer note: :id is assumed to exist in the async function check() of permissions.ts
353353
"file/:model/:location/:id",
354354
function (req, res) {
355355
return __awaiter(this, void 0, void 0, function () {
@@ -419,4 +419,4 @@ function controller(fng, processArgs, options) {
419419
// but in our case, we have nothing, so we can simply...
420420
return retVal;
421421
}
422-
exports.controller = controller;
422+
export default { controller: controller, FileSchema: FileSchema };

lib/fng-jq-upload.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// TODO set busboy filesize limit
2-
import express = require("express");
3-
import mongoose = require("mongoose");
4-
import mongodb = require("mongodb");
5-
import path = require("path");
6-
import busboy = require("busboy");
7-
import * as ims from "imagemagick-stream";
2+
import express from "express";
3+
import mongoose from "mongoose";
4+
import * as mongodb from "mongodb";
5+
import path from "path";
6+
import busboy from "busboy";
7+
import ims from "imagemagick-stream";
88
import * as stream from "stream";
99

10-
import { fngServer } from "forms-angular/dist/server";
10+
import type { fngServer } from "forms-angular/dist/server/index.js";
1111
import { BusboyConfig } from "busboy";
1212

1313
// the numeric values are written to the document property that stores the reference to the file (which
@@ -437,3 +437,5 @@ export function controller(
437437
// but in our case, we have nothing, so we can simply...
438438
return retVal;
439439
}
440+
441+
export default { controller, FileSchema };

package.json

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "fng-jq-upload",
33
"version": "0.12.0-beta.322",
4+
"type": "module",
45
"author": {
56
"name": "Mark Chapman",
67
"email": "support@forms-angular.org"
@@ -10,46 +11,46 @@
1011
"test": "grunt test"
1112
},
1213
"dependencies": {
13-
"blueimp-file-upload":"^9.34.0",
14-
"busboy":"^1.6.0",
15-
"imagemagick-stream":"^4.1.1",
16-
"jquery":"^3.7.1",
14+
"blueimp-file-upload": "^9.34.0",
15+
"busboy": "^1.6.0",
16+
"imagemagick-stream": "^4.1.1",
17+
"jquery": "^3.7.1",
1718
"lodash": "^4.17.21"
1819
},
1920
"devDependencies": {
2021
"@types/busboy": "^1.5.4",
2122
"@types/express": "^4.17.21",
2223
"@types/node": "^20.14.8",
23-
"angular":"^1.8.3",
24-
"angular-animate":"^1.8.3",
25-
"angular-elastic":"^2.5.1",
26-
"angular-messages":"^1.8.3",
27-
"angular-mocks":"^1.8.3",
28-
"angular-sanitize":"^1.8.3",
24+
"angular": "^1.8.3",
25+
"angular-animate": "^1.8.3",
26+
"angular-elastic": "^2.5.1",
27+
"angular-messages": "^1.8.3",
28+
"angular-mocks": "^1.8.3",
29+
"angular-sanitize": "^1.8.3",
2930
"angular-ui-bootstrap": "1.3.2 || 2.5.6",
30-
"async":"^3.2.5",
31-
"body-parser":"^1.20.2",
32-
"express":"^4.19.2",
31+
"async": "^3.2.5",
32+
"body-parser": "^1.20.2",
33+
"express": "^4.19.2",
3334
"forms-angular": "0.12.0-beta.322",
3435
"grunt": "^1.6.1",
3536
"grunt-angular-templates": "^1.2.0",
36-
"grunt-contrib-concat":"^2.1.0",
37-
"grunt-contrib-jshint":"^3.2.0",
38-
"grunt-contrib-uglify":"^5.2.2",
37+
"grunt-contrib-concat": "^2.1.0",
38+
"grunt-contrib-jshint": "^3.2.0",
39+
"grunt-contrib-uglify": "^5.2.2",
3940
"grunt-karma": "^4.0.2",
40-
"grunt-mocha-test":"^0.13.3",
41-
"jasmine-core":"^5.1.2",
42-
"karma":"^6.4.3",
41+
"grunt-mocha-test": "^0.13.3",
42+
"jasmine-core": "^5.1.2",
43+
"karma": "^6.4.3",
4344
"karma-chrome-launcher": "^3.2.0",
44-
"karma-jasmine":"^5.1.0",
45-
"karma-junit-reporter":"^2.0.1",
46-
"karma-ng-html2js-preprocessor":"^1.0.0",
45+
"karma-jasmine": "^5.1.0",
46+
"karma-junit-reporter": "^2.0.1",
47+
"karma-ng-html2js-preprocessor": "^1.0.0",
4748
"mocha": "^10.4.0",
4849
"mongodb": "=5.9.1",
4950
"mongoose": "=7.6.8",
50-
"ng-infinite-scroll":"^1.3.0",
51+
"ng-infinite-scroll": "^1.3.0",
5152
"semver": "^7.6.2",
52-
"supertest":"^7.0.0"
53+
"supertest": "^7.0.0"
5354
},
5455
"overrides": {
5556
"array-flatten": "npm:@socketregistry/array-flatten@^1",
@@ -94,4 +95,4 @@
9495
"uploader"
9596
],
9697
"license": "MIT"
97-
}
98+
}

0 commit comments

Comments
 (0)