Update webpack and testing frameworks

This commit is contained in:
Dolan
2021-03-31 21:27:40 +01:00
parent 488711dae0
commit fceefcf290
7 changed files with 1092 additions and 4108 deletions

1
.nycrc
View File

@ -21,6 +21,5 @@
],
"cache": true,
"all": true,
"instrument": false,
"sourceMap": true
}

View File

@ -12,9 +12,7 @@
<script>
function generate() {
const doc = new docx.Document();
const doc = new Document({
const doc = new docx.Document({
sections: [
{
children: [

5104
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,22 +5,21 @@
"main": "build/index.js",
"scripts": {
"pretest": "rimraf ./build",
"test": "mocha-webpack \"src/**/*.ts\"",
"test": "mocha -r ts-node/register -r tsconfig-paths/register \"src/**/*.ts\"",
"test.coverage": "nyc npm test",
"test.watch": "npm test -- --watch",
"prepublishOnly": "npm run build --production",
"lint": "tslint --project .",
"build": "npm run webpack && npm run fix-types",
"tsc": "rimraf ./build && tsc -p .",
"webpack": "rimraf ./build && webpack",
"demo": "npm run build && npm run ts-node ./demo",
"build": "npm run webpack",
"webpack": "rimraf ./build && webpack --config ./webpack.config.ts",
"demo": "npm run build && npm run ts-node --skip-project ./demo",
"typedoc": "rimraf ./build && typedoc src/index.ts --tsconfig tsconfig.typedoc.json",
"style": "prettier -l \"src/**/*.ts\"",
"style.fix": "npm run style -- --write",
"fix-types": "ts-node scripts/types-absolute-fixer.ts",
"e2e": "ts-node scripts/e2e.ts",
"serve.docs": "cd docs && docsify serve",
"ts-node": "ts-node"
"ts-node": "ts-node --skip-project"
},
"pre-commit": [
"style",
@ -68,17 +67,16 @@
"@types/request-promise": "^4.1.42",
"@types/sinon": "^9.0.4",
"@types/webpack": "^5.0.0",
"awesome-typescript-loader": "^3.4.1",
"buffer": "^6.0.3",
"chai": "^3.5.0",
"docsify-cli": "^4.3.0",
"glob": "^7.1.2",
"istanbul-instrumenter-loader": "^3.0.1",
"jszip": "^3.1.5",
"mocha": "^5.2.0",
"mocha-webpack": "^1.0.1",
"mocha": "^8.3.2",
"nyc": "^15.1.0",
"pre-commit": "^1.2.2",
"prettier": "^2.1.2",
"process": "^0.11.10",
"prompt": "^1.0.0",
"replace-in-file": "^3.1.0",
"request": "^2.88.0",
@ -86,12 +84,16 @@
"rimraf": "^3.0.2",
"shelljs": "^0.8.4",
"sinon": "^10.0.0",
"stream-browserify": "^3.0.0",
"ts-loader": "^8.1.0",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"tslint": "^6.1.3",
"tslint-immutable": "^6.0.1",
"typedoc": "^0.20.29",
"typescript": "4.2.3",
"webpack": "^3.10.0"
"webpack": "^5.28.0",
"webpack-cli": "^4.6.0"
},
"engines": {
"node": ">=10"

View File

@ -1,7 +1,7 @@
import { assert, expect } from "chai";
import * as sinon from "sinon";
import { Formatter } from "export/formatter";
import { Formatter } from "@export/formatter";
import { Paragraph, TextRun } from "file";
import { CoreProperties } from "file/core-properties";
import { Attributes } from "file/xml-components";

View File

@ -13,8 +13,10 @@
"noUnusedParameters": true,
"baseUrl": "./src",
"paths": {
"/*": ["./*"]
"/*": ["./*"],
"convenience-functions": ["./convenience-functions"],
"@export/*": ["./export/*"]
}
},
"exclude": ["node_modules", "tests", "**/_*", "demo", "scripts", "webpack.config.ts"]
"include": ["src"]
}

View File

@ -1,8 +1,9 @@
// tslint:disable:no-object-literal-type-assertion
import * as path from "path";
import { Configuration } from "webpack";
import { Configuration, ProvidePlugin } from "webpack";
const configuration: Configuration = {
mode: "production",
module.exports = {
entry: "./src/index.ts",
output: {
@ -10,34 +11,36 @@ module.exports = {
filename: "index.js",
libraryTarget: "umd",
library: "docx",
globalObject: "this",
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
extensions: [".ts", ".js"],
modules: [path.resolve("./src"), "node_modules"],
fallback: {
buffer: require.resolve("buffer"),
stream: require.resolve("stream-browserify"),
},
},
module: {
rules: [
{
test: /\.ts$/,
loaders: ["awesome-typescript-loader"],
loader: "ts-loader",
options: {
configFile: "tsconfig.json",
},
// For coverage testing
...(process.env.NODE_ENV !== "production"
? [
{
test: /\.(ts)/,
include: path.resolve("src"),
loader: "istanbul-instrumenter-loader",
enforce: "post",
exclude: [/node_modules/],
},
]
: []),
],
},
// Because docx is now targetting web
// target: 'node',
} as Configuration;
plugins: [
// fix "process is not defined" error
new ProvidePlugin({
process: "process/browser",
}),
],
};
module.exports = configuration;