Skip to content

Commit 33dcad9

Browse files
committed
Update to webpack 5 + typescript 4 + tsickle 0.46.3. Fixed compilation errors and tests.
1 parent 0a8c60f commit 33dcad9

7 files changed

+52
-63
lines changed

package.json

+30-30
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,40 @@
1515
"testEnvironment": "node"
1616
},
1717
"peerDependencies": {
18-
"typescript": "~3.8.3",
19-
"webpack": "^4.29.1"
18+
"typescript": "~4.9.4",
19+
"webpack": "^5.75.0"
2020
},
2121
"devDependencies": {
22-
"@babel/core": "^7.2.2",
23-
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
24-
"@babel/plugin-transform-runtime": "^7.2.0",
25-
"@babel/preset-env": "^7.3.1",
26-
"@babel/preset-typescript": "^7.1.0",
27-
"@babel/runtime": "^7.3.1",
28-
"@types/fs-extra": "^5.0.5",
29-
"@types/loader-utils": "^1.1.3",
30-
"@types/node": "^11.11.3",
31-
"babel-jest": "^24.1.0",
32-
"babel-loader": "^8.0.5",
33-
"closure-webpack-plugin": "^2.0.0-rc.17",
34-
"eslint": "^5.13.0",
35-
"eslint-config-standard": "^12.0.0",
36-
"eslint-plugin-import": "^2.16.0",
37-
"eslint-plugin-jest": "^22.2.2",
38-
"eslint-plugin-node": "^8.0.1",
39-
"eslint-plugin-promise": "^4.0.1",
40-
"eslint-plugin-standard": "^4.0.0",
41-
"google-closure-compiler": "^20181231.0.0-webpack-beta",
42-
"jest": "^24.1.0",
43-
"memory-fs": "^0.4.1",
22+
"@babel/core": "^7.20.12",
23+
"@babel/plugin-transform-modules-commonjs": "^7.20.11",
24+
"@babel/plugin-transform-runtime": "^7.19.6",
25+
"@babel/preset-env": "^7.20.2",
26+
"@babel/preset-typescript": "^7.18.6",
27+
"@babel/runtime": "^7.20.7",
28+
"@types/fs-extra": "^11.0.1",
29+
"@types/node": "^18.11.18",
30+
"babel-jest": "^29.3.1",
31+
"babel-loader": "^9.1.2",
32+
"closure-webpack-plugin": "^2.6.1",
33+
"eslint": "^8.31.0",
34+
"eslint-config-standard": "^17.0.0",
35+
"eslint-plugin-import": "^2.27.4",
36+
"eslint-plugin-jest": "^27.2.1",
37+
"eslint-plugin-node": "^11.1.0",
38+
"eslint-plugin-promise": "^6.1.1",
39+
"eslint-plugin-standard": "^4.1.0",
40+
"google-closure-compiler": "^20230103.0.0",
41+
"jest": "^29.3.1",
42+
"memory-fs": "^0.5.0",
4443
"postscribe": "^2.0.8",
45-
"source-map": "^0.6.1",
46-
"ts-loader": "^5.3.3",
47-
"typescript": "~3.8.3",
48-
"webpack": "^4.29.1"
44+
"source-map": "^0.7.4",
45+
"ts-loader": "^9.4.2",
46+
"typescript": "~4.9.4",
47+
"webpack": "^5.75.0"
4948
},
5049
"dependencies": {
51-
"fs-extra": "^7.0.1",
52-
"tsickle": "^0.38.1"
50+
"fs-extra": "^11.1.0",
51+
"schema-utils": "^4.0.0",
52+
"tsickle": "^0.46.3"
5353
}
5454
}

src/index.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import fs from "fs-extra";
22
import * as path from "path";
3-
import { getOptions, OptionObject } from "loader-utils";
4-
import validateOptions = require("schema-utils");
5-
import tsickle = require("tsickle");
3+
import { validate } from "schema-utils";
4+
import * as tsickle from "tsickle";
65
import ts from "typescript";
76
import { EOL } from "os";
8-
import webpack = require("webpack");
7+
import webpack from "webpack";
98
import { fixCode, fixExtern } from "./fix-output";
109
import { jsToTS, tsToJS } from "./path-utils";
11-
import { TcpSocketConnectOpts } from "net";
10+
import { JSONSchema7 } from "json-schema";
1211

1312
const LOADER_NAME = "tsickle-loader";
1413
const DEFAULT_EXTERN_DIR = "dist/externs";
1514
const EXTERNS_FILE_NAME = "externs.js";
1615
const DEFAULT_CONFIG_FILE = "tsconfig.json";
1716

18-
const optionsSchema = {
17+
const optionsSchema: JSONSchema7 = {
1918
type: "object",
2019
properties: {
2120
tsconfig: {
@@ -34,16 +33,16 @@ const optionsSchema = {
3433
}
3534
};
3635

37-
interface RealOptions extends OptionObject {
36+
interface RealOptions {
3837
externDir: string;
3938
tsconfig: string;
4039
externFile: string;
4140
compilerConfig: ReturnType<typeof ts.parseJsonConfigFileContent>;
4241
}
4342

44-
const setup = (loaderCTX: webpack.loader.LoaderContext): RealOptions => {
45-
const options = getOptions(loaderCTX);
46-
validateOptions(optionsSchema, options, LOADER_NAME);
43+
const setup = (loaderCTX: LoaderCTX): RealOptions => {
44+
const options = loaderCTX.getOptions();
45+
validate(optionsSchema, options, { name: LOADER_NAME });
4746

4847
const externDir =
4948
options.externDir != null ? options.externDir : DEFAULT_EXTERN_DIR;
@@ -78,7 +77,7 @@ const setup = (loaderCTX: webpack.loader.LoaderContext): RealOptions => {
7877
};
7978
};
8079

81-
type LoaderCTX = webpack.loader.LoaderContext;
80+
type LoaderCTX = webpack.LoaderContext<RealOptions>;
8281

8382
const handleDiagnostics = (
8483
ctx: LoaderCTX,
@@ -92,13 +91,13 @@ const handleDiagnostics = (
9291
);
9392

9493
if (type === "error") {
95-
ctx.emitError(Error(formatted));
94+
ctx.emitError(new Error(formatted));
9695
} else {
97-
ctx.emitWarning(formatted);
96+
ctx.emitWarning(new Error(formatted));
9897
}
9998
};
10099

101-
const tsickleLoader: webpack.loader.Loader = function(
100+
const tsickleLoader = function (
102101
this: LoaderCTX,
103102
_source: string | Buffer
104103
) {
@@ -131,15 +130,16 @@ const tsickleLoader: webpack.loader.Loader = function(
131130
pathToModuleName: (name: string) => name,
132131
fileNameToModuleId: (name: string) => name,
133132
options: {}, // TODO: set possible options here
134-
es5Mode: true,
135133
moduleResolutionHost: compilerHost,
136134
googmodule: false,
137135
transformDecorators: true,
138136
transformTypesToClosure: true,
139137
typeBlackListPaths: new Set(),
140138
untyped: false,
141139
logWarning: warning =>
142-
handleDiagnostics(this, [warning], diagnosticsHost, "warning")
140+
handleDiagnostics(this, [warning], diagnosticsHost, "warning"),
141+
generateExtraSuppressions: true,
142+
rootDirsRelative: (f: string) => f,
143143
};
144144

145145
const jsFiles = new Map<string, string>();

src/schema-utils.d.ts

-12
This file was deleted.

test/compiler.js

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const Memoryfs = require('memory-fs')
55
module.exports = (fixture, options = {}) => {
66
const compiler = webpack({
77
stats: {
8-
// Examine all modules
9-
maxModules: Infinity,
108
// Display bailout reasons
119
optimizationBailout: true
1210
},

test/loader.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const compiler = require('./compiler.js')
22
const fs = require('fs-extra')
33
const path = require('path')
44
const ClosureCompilerPlugin = require('closure-webpack-plugin')
5+
jest.setTimeout(20000);
56

67
test('Converts a simple es6 function', async () => {
78
const [output] = await compiler('examples/hello-world.ts')
@@ -37,7 +38,7 @@ test('It will correctly collapse unnecessary modules (tree shaking)', async () =
3738
})
3839

3940
expect(output).toContain('myRealExport')
40-
}, 10e3)
41+
})
4142

4243
test('will work with closure compiler plugin', async () => {
4344
const externDir = path.resolve(__dirname, 'tmp', 'externs-' + Math.floor(Math.random() * 10))
@@ -75,6 +76,6 @@ test('will work with closure compiler plugin', async () => {
7576
externDir
7677
})
7778

78-
fs.writeFileSync('./complex-example.js', output)
79+
fs.writeFileSync(path.resolve(__dirname,'tmp/complex-example.js'), output)
7980
expect(output).toBeTruthy()
80-
}, 15e3) // this can be *very* slow
81+
}) // this can be *very* slow

test/tsconfig.explicit.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"module": "es2015",
77
"moduleResolution": "node",
88
"target": "es5",
9+
"rootDir": "."
910
}
1011
}

test/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"compilerOptions": {
66
"module": "commonjs",
77
"target": "es5",
8+
"rootDir": "."
89
}
910
}

0 commit comments

Comments
 (0)