Skip to content

Commit 51981e7

Browse files
liangchunnjohnnyreilly
authored andcommitted
refactor(object-spread): use spread instead of assign (#194)
* refactor(object-spread): use spread instead of assign * 1.0.0-alpha.1
1 parent 683ed7a commit 51981e7

File tree

8 files changed

+78
-82
lines changed

8 files changed

+78
-82
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v1.0.0-alpha.1
2+
3+
* [Use object-spread instead of `Object.assign`](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/194) (#194)
4+
15
## v1.0.0-alpha.0
26

37
* [Add support for webpack 5](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/166)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fork-ts-checker-webpack-plugin",
3-
"version": "1.0.0-alpha.0",
3+
"version": "1.0.0-alpha.1",
44
"description": "Runs typescript type checker and linter on separate process.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/cluster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ for (let num = 0; num < division; num++) {
1414
workers.push(
1515
childProcess.fork(path.resolve(__dirname, './service.js'), [], {
1616
execArgv: ['--max-old-space-size=' + process.env.MEMORY_LIMIT],
17-
env: Object.assign({}, process.env, { WORK_NUMBER: num }),
17+
env: { ...process.env, WORK_NUMBER: num },
1818
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
1919
})
2020
);

src/formatter/codeframeFormatter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export function createCodeframeFormatter(options: any) {
3232
source,
3333
message.line!, // Assertion: `codeFrame` allows passing undefined, typings are incorrect
3434
message.character!,
35-
Object.assign({}, options || {}, { highlightCode: useColors })
35+
{
36+
...(options || {}),
37+
highlightCode: useColors
38+
}
3639
)
3740
.split('\n')
3841
.map(str => ' ' + str)

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ForkTsCheckerWebpackPlugin {
114114

115115
constructor(options?: Partial<Options>) {
116116
options = options || ({} as Options);
117-
this.options = Object.assign({}, options);
117+
this.options = { ...options };
118118

119119
this.tsconfig = options.tsconfig || './tsconfig.json';
120120
this.compilerOptions =
@@ -489,7 +489,8 @@ class ForkTsCheckerWebpackPlugin {
489489
this.workersNumber > 1
490490
? []
491491
: ['--max-old-space-size=' + this.memoryLimit],
492-
env: Object.assign({}, process.env, {
492+
env: {
493+
...process.env,
493494
TSCONFIG: this.tsconfigPath,
494495
COMPILER_OPTIONS: JSON.stringify(this.compilerOptions),
495496
TSLINT: this.tslintPath || '',
@@ -499,7 +500,7 @@ class ForkTsCheckerWebpackPlugin {
499500
MEMORY_LIMIT: this.memoryLimit,
500501
CHECK_SYNTACTIC_ERRORS: this.checkSyntacticErrors,
501502
VUE: this.vue
502-
}),
503+
},
503504
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
504505
}
505506
);

test/integration/index.spec.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,30 @@ describe('[INTEGRATION] index', function() {
3535
happyPackMode,
3636
entryPoint = './src/index.ts'
3737
) {
38-
plugin = new ForkTsCheckerWebpackPlugin(
39-
Object.assign({}, options, { silent: true })
40-
);
38+
plugin = new ForkTsCheckerWebpackPlugin({ ...options, silent: true });
4139

4240
var tsLoaderOptions = happyPackMode
4341
? { happyPackMode: true, silent: true }
4442
: { transpileOnly: true, silent: true };
4543

46-
return webpack(
47-
Object.assign(webpackMajorVersion >= 4 ? { mode: 'development' } : {}, {
48-
context: path.resolve(__dirname, './project'),
49-
entry: entryPoint,
50-
output: {
51-
path: path.resolve(__dirname, '../../tmp')
52-
},
53-
module: {
54-
rules: [
55-
{
56-
test: /\.tsx?$/,
57-
loader: 'ts-loader',
58-
options: tsLoaderOptions
59-
}
60-
]
61-
},
62-
plugins: [plugin]
63-
})
64-
);
44+
return webpack({
45+
...(webpackMajorVersion >= 4 ? { mode: 'development' } : {}),
46+
context: path.resolve(__dirname, './project'),
47+
entry: entryPoint,
48+
output: {
49+
path: path.resolve(__dirname, '../../tmp')
50+
},
51+
module: {
52+
rules: [
53+
{
54+
test: /\.tsx?$/,
55+
loader: 'ts-loader',
56+
options: tsLoaderOptions
57+
}
58+
]
59+
},
60+
plugins: [plugin]
61+
});
6562
}
6663

6764
/**

test/integration/vue.spec.js

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,45 @@ describe('[INTEGRATION] vue', function() {
2222
var checker;
2323

2424
function createCompiler(options) {
25-
plugin = new ForkTsCheckerWebpackPlugin(
26-
Object.assign({}, options, { silent: true })
27-
);
28-
29-
compiler = webpack(
30-
Object.assign(
31-
webpackMajorVersion >= 4 ? { mode: 'development' } : {},
32-
{
33-
context: path.resolve(__dirname, './vue'),
34-
entry: './src/index.ts',
35-
output: {
36-
path: path.resolve(__dirname, '../../tmp')
37-
},
38-
resolve: {
39-
extensions: ['.ts', '.js', '.vue', '.json'],
40-
alias: {
41-
'@': path.resolve(__dirname, './vue/src')
42-
}
43-
},
44-
module: {
45-
rules: [
46-
{
47-
test: /\.vue$/,
48-
loader: 'vue-loader'
49-
},
50-
{
51-
test: /\.ts$/,
52-
loader: 'ts-loader',
53-
options: {
54-
appendTsSuffixTo: [/\.vue$/],
55-
transpileOnly: true,
56-
silent: true
57-
}
58-
},
59-
{
60-
test: /\.css$/,
61-
loader: 'css-loader'
25+
plugin = new ForkTsCheckerWebpackPlugin({ ...options, silent: true });
26+
27+
compiler = webpack({
28+
...(webpackMajorVersion >= 4 ? { mode: 'development' } : {}),
29+
context: path.resolve(__dirname, './vue'),
30+
entry: './src/index.ts',
31+
output: {
32+
path: path.resolve(__dirname, '../../tmp')
33+
},
34+
resolve: {
35+
extensions: ['.ts', '.js', '.vue', '.json'],
36+
alias: {
37+
'@': path.resolve(__dirname, './vue/src')
38+
}
39+
},
40+
module: {
41+
rules: [
42+
{
43+
test: /\.vue$/,
44+
loader: 'vue-loader'
45+
},
46+
{
47+
test: /\.ts$/,
48+
loader: 'ts-loader',
49+
options: {
50+
appendTsSuffixTo: [/\.vue$/],
51+
transpileOnly: true,
52+
silent: true
6253
}
63-
]
64-
},
65-
plugins: webpackMajorVersion >= 4 ? [new VueLoaderPlugin(), plugin] : [plugin],
66-
}
67-
));
54+
},
55+
{
56+
test: /\.css$/,
57+
loader: 'css-loader'
58+
}
59+
]
60+
},
61+
plugins:
62+
webpackMajorVersion >= 4 ? [new VueLoaderPlugin(), plugin] : [plugin]
63+
});
6864

6965
files = {
7066
'example.vue': path.resolve(compiler.context, 'src/example.vue'),

test/unit/NormalizedMessage.spec.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,11 @@ describe('[UNIT] NormalizedMessage', function() {
5151
expect(jsonMessage).to.be.instanceof(NormalizedMessage);
5252
expect(jsonMessage.type).to.be.equal(diagnosticMessage.type);
5353
expect(jsonMessage.code).to.be.equal(diagnosticMessage.code);
54-
expect(jsonMessage.severity).to.be.equal(
55-
diagnosticMessage.severity
56-
);
57-
expect(jsonMessage.content).to.be.equal(
58-
diagnosticMessage.content
59-
);
54+
expect(jsonMessage.severity).to.be.equal(diagnosticMessage.severity);
55+
expect(jsonMessage.content).to.be.equal(diagnosticMessage.content);
6056
expect(jsonMessage.file).to.be.equal(diagnosticMessage.file);
6157
expect(jsonMessage.line).to.be.equal(diagnosticMessage.line);
62-
expect(jsonMessage.character).to.be.equal(
63-
diagnosticMessage.character
64-
);
58+
expect(jsonMessage.character).to.be.equal(diagnosticMessage.character);
6559
});
6660

6761
it('should check type', function() {
@@ -176,9 +170,10 @@ describe('[UNIT] NormalizedMessage', function() {
176170
it('should compare messages', function() {
177171
var messageA = diagnosticMessage;
178172
function buildMessage(diff) {
179-
return NormalizedMessage.createFromJSON(
180-
Object.assign({}, messageA.toJSON(), diff)
181-
);
173+
return NormalizedMessage.createFromJSON({
174+
...messageA.toJSON(),
175+
...diff
176+
});
182177
}
183178

184179
expect(NormalizedMessage.compare(messageA, undefined)).to.be.greaterThan(0);

0 commit comments

Comments
 (0)