Skip to content

Commit d508fb6

Browse files
committed
Upgrade XO and apply changes
1 parent 01d22e2 commit d508fb6

File tree

6 files changed

+56
-59
lines changed

6 files changed

+56
-59
lines changed

index.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const configProperties = {
4444
required: true,
4545
isValid(compile) {
4646
return compile === false || compile === 'tsc';
47-
}
47+
},
4848
},
4949
rewritePaths: {
5050
required: true,
@@ -53,20 +53,18 @@ const configProperties = {
5353
return false;
5454
}
5555

56-
return Object.entries(rewritePaths).every(([from, to]) => {
57-
return from.endsWith('/') && typeof to === 'string' && to.endsWith('/');
58-
});
59-
}
56+
return Object.entries(rewritePaths).every(([from, to]) => from.endsWith('/') && typeof to === 'string' && to.endsWith('/'));
57+
},
6058
},
6159
extensions: {
6260
required: false,
6361
isValid(extensions) {
64-
return Array.isArray(extensions) &&
65-
extensions.length > 0 &&
66-
extensions.every(ext => typeof ext === 'string' && ext !== '') &&
67-
new Set(extensions).size === extensions.length;
68-
}
69-
}
62+
return Array.isArray(extensions)
63+
&& extensions.length > 0
64+
&& extensions.every(ext => typeof ext === 'string' && ext !== '')
65+
&& new Set(extensions).size === extensions.length;
66+
},
67+
},
7068
};
7169

7270
module.exports = ({negotiateProtocol}) => {
@@ -86,12 +84,12 @@ module.exports = ({negotiateProtocol}) => {
8684
const {
8785
extensions = ['ts'],
8886
rewritePaths: relativeRewritePaths,
89-
compile
87+
compile,
9088
} = config;
9189

9290
const rewritePaths = Object.entries(relativeRewritePaths).map(([from, to]) => [
9391
path.join(protocol.projectDir, from),
94-
path.join(protocol.projectDir, to)
92+
path.join(protocol.projectDir, to),
9593
]);
9694
const testFileExtension = new RegExp(`\\.(${extensions.map(ext => escapeStringRegexp(ext)).join('|')})$`);
9795

@@ -102,13 +100,13 @@ module.exports = ({negotiateProtocol}) => {
102100
}
103101

104102
return {
105-
extensions: extensions.slice(),
106-
rewritePaths: rewritePaths.slice()
103+
extensions: [...extensions],
104+
rewritePaths: [...rewritePaths],
107105
};
108106
},
109107

110108
get extensions() {
111-
return extensions.slice();
109+
return [...extensions];
112110
},
113111

114112
ignoreChange(filePath) {
@@ -139,14 +137,14 @@ module.exports = ({negotiateProtocol}) => {
139137
filePatterns: [
140138
...filePatterns,
141139
'!**/*.d.ts',
142-
...Object.values(relativeRewritePaths).map(to => `!${to}**`)
140+
...Object.values(relativeRewritePaths).map(to => `!${to}**`),
143141
],
144142
ignoredByWatcherPatterns: [
145143
...ignoredByWatcherPatterns,
146-
...Object.values(relativeRewritePaths).map(to => `${to}**/*.js.map`)
147-
]
144+
...Object.values(relativeRewritePaths).map(to => `${to}**/*.js.map`),
145+
],
148146
};
149-
}
147+
},
150148
};
151149
},
152150

@@ -169,8 +167,8 @@ module.exports = ({negotiateProtocol}) => {
169167
// TODO: Support JSX preserve mode — https://www.typescriptlang.org/docs/handbook/jsx.html
170168
const rewritten = `${to}${ref.slice(from.length)}`.replace(testFileExtension, '.js');
171169
return requireFn(rewritten);
172-
}
170+
},
173171
};
174-
}
172+
},
175173
};
176174
};

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"c8": "^7.7.1",
2828
"del": "^6.0.0",
2929
"typescript": "^4.2.4",
30-
"xo": "^0.38.2"
30+
"xo": "^0.46.3"
3131
},
3232
"c8": {
3333
"reporter": [
@@ -47,7 +47,9 @@
4747
"test/broken-fixtures"
4848
],
4949
"rules": {
50-
"import/order": "off"
50+
"import/extensions": "off",
51+
"import/order": "off",
52+
"unicorn/prefer-module": "off"
5153
}
5254
}
5355
}

test/_with-provider.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@ const path = require('path');
22
const pkg = require('../package.json');
33
const makeProvider = require('..');
44

5-
const createProviderMacro = (identifier, avaVersion, projectDir = __dirname) => {
6-
return (t, run) => run(t, makeProvider({
7-
negotiateProtocol(identifiers, {version}) {
8-
t.true(identifiers.includes(identifier));
9-
t.is(version, pkg.version);
10-
return {
11-
ava: {avaVersion},
12-
identifier,
13-
normalizeGlobPatterns: patterns => patterns,
14-
async findFiles({patterns}) {
15-
return patterns.map(file => path.join(projectDir, file));
16-
},
17-
projectDir
18-
};
19-
}
20-
}));
21-
};
5+
const createProviderMacro = (identifier, avaVersion, projectDir = __dirname) => (t, run) => run(t, makeProvider({
6+
negotiateProtocol(identifiers, {version}) {
7+
t.true(identifiers.includes(identifier));
8+
t.is(version, pkg.version);
9+
return {
10+
ava: {avaVersion},
11+
identifier,
12+
normalizeGlobPatterns: patterns => patterns,
13+
async findFiles({patterns}) {
14+
return patterns.map(file => path.join(projectDir, file));
15+
},
16+
projectDir,
17+
};
18+
},
19+
}));
2220

2321
module.exports = createProviderMacro;

test/compilation.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,24 @@ test.before('deleting compiled files', async t => {
1212
t.log(await del('test/broken-fixtures/typescript/compiled'));
1313
});
1414

15-
const compile = async provider => {
16-
return {
17-
state: await provider.main({
18-
config: {
19-
rewritePaths: {
20-
'ts/': 'typescript/',
21-
'compiled/': 'typescript/compiled/'
22-
},
23-
compile: 'tsc'
24-
}
25-
}).compile()
26-
};
27-
};
15+
const compile = async provider => ({
16+
state: await provider.main({
17+
config: {
18+
rewritePaths: {
19+
'ts/': 'typescript/',
20+
'compiled/': 'typescript/compiled/',
21+
},
22+
compile: 'tsc',
23+
},
24+
}).compile(),
25+
});
2826

2927
test('worker(): load rewritten paths files', withProvider, async (t, provider) => {
3028
const {state} = await compile(provider);
3129
const {stdout, stderr} = await execa.node(
3230
path.join(__dirname, 'fixtures/install-and-load'),
3331
[JSON.stringify(state), path.join(__dirname, 'fixtures/ts', 'file.ts')],
34-
{cwd: path.join(__dirname, 'fixtures')}
32+
{cwd: path.join(__dirname, 'fixtures')},
3533
);
3634
if (stderr.length > 0) {
3735
t.log(stderr);
@@ -45,7 +43,7 @@ test('worker(): runs compiled files', withProvider, async (t, provider) => {
4543
const {stdout, stderr} = await execa.node(
4644
path.join(__dirname, 'fixtures/install-and-load'),
4745
[JSON.stringify(state), path.join(__dirname, 'fixtures/compiled', 'index.ts')],
48-
{cwd: path.join(__dirname, 'fixtures')}
46+
{cwd: path.join(__dirname, 'fixtures')},
4947
);
5048
if (stderr.length > 0) {
5149
t.log(stderr);

test/fixtures/install-and-load.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
const path = require('path');
2+
const process = require('process');
23
const makeProvider = require('../..');
34

45
const provider = makeProvider({
56
negotiateProtocol() {
67
return {identifier: 'ava-3.2', ava: {version: '3.15.0'}, projectDir: __dirname};
7-
}
8+
},
89
});
910

1011
const worker = provider.worker({
1112
extensionsToLoadAsModules: [],
12-
state: JSON.parse(process.argv[2])
13+
state: JSON.parse(process.argv[2]),
1314
});
1415

1516
const ref = path.resolve(process.argv[3]);

test/protocol-ava-3.2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ test('main() updateGlobs()', withProvider, (t, provider) => {
8181
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}});
8282
t.snapshot(main.updateGlobs({
8383
filePatterns: ['src/test.ts'],
84-
ignoredByWatcherPatterns: ['assets/**']
84+
ignoredByWatcherPatterns: ['assets/**'],
8585
}));
8686
});

0 commit comments

Comments
 (0)