Skip to content

Commit 56e3b15

Browse files
committed
Upgrade XO and apply fixes
1 parent 1ae15b2 commit 56e3b15

File tree

5 files changed

+43
-43
lines changed

5 files changed

+43
-43
lines changed

index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {pathToFileURL} from 'node:url';
44
import escapeStringRegexp from 'escape-string-regexp';
55
import {execa} from 'execa';
66

7-
const pkg = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url)));
8-
const help = `See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md`;
7+
const package_ = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url)));
8+
const help = `See https://github.com/avajs/typescript/blob/v${package_.version}/README.md`;
99

1010
function isPlainObject(x) {
1111
return x !== null && typeof x === 'object' && Reflect.getPrototypeOf(x) === Object.prototype;
@@ -36,8 +36,8 @@ function validate(target, properties) {
3636
}
3737
}
3838

39-
async function compileTypeScript(projectDir) {
40-
return execa('tsc', ['--incremental'], {preferLocal: true, cwd: projectDir});
39+
async function compileTypeScript(projectDirectory) {
40+
return execa('tsc', ['--incremental'], {preferLocal: true, cwd: projectDirectory});
4141
}
4242

4343
const configProperties = {
@@ -62,7 +62,7 @@ const configProperties = {
6262
isValid(extensions) {
6363
return Array.isArray(extensions)
6464
&& extensions.length > 0
65-
&& extensions.every(ext => typeof ext === 'string' && ext !== '')
65+
&& extensions.every(extension => typeof extension === 'string' && extension !== '')
6666
&& new Set(extensions).size === extensions.length;
6767
},
6868
},
@@ -75,7 +75,7 @@ const changeInterpretations = Object.freeze(Object.assign(Object.create(null), {
7575
}));
7676

7777
export default function typescriptProvider({negotiateProtocol}) {
78-
const protocol = negotiateProtocol(['ava-6'], {version: pkg.version});
78+
const protocol = negotiateProtocol(['ava-6'], {version: package_.version});
7979
if (protocol === null) {
8080
return;
8181
}
@@ -98,7 +98,7 @@ export default function typescriptProvider({negotiateProtocol}) {
9898
path.join(protocol.projectDir, from),
9999
path.join(protocol.projectDir, to),
100100
]);
101-
const testFileExtension = new RegExp(`\\.(${extensions.map(ext => escapeStringRegexp(ext)).join('|')})$`);
101+
const testFileExtension = new RegExp(`\\.(${extensions.map(extension => escapeStringRegexp(extension)).join('|')})$`);
102102

103103
const watchMode = {
104104
changeInterpretations,
@@ -245,21 +245,21 @@ export default function typescriptProvider({negotiateProtocol}) {
245245

246246
worker({extensionsToLoadAsModules, state: {extensions, rewritePaths}}) {
247247
const importJs = extensionsToLoadAsModules.includes('js');
248-
const testFileExtension = new RegExp(`\\.(${extensions.map(ext => escapeStringRegexp(ext)).join('|')})$`);
248+
const testFileExtension = new RegExp(`\\.(${extensions.map(extension => escapeStringRegexp(extension)).join('|')})$`);
249249

250250
return {
251-
canLoad(ref) {
252-
return testFileExtension.test(ref) && rewritePaths.some(([from]) => ref.startsWith(from));
251+
canLoad(reference) {
252+
return testFileExtension.test(reference) && rewritePaths.some(([from]) => reference.startsWith(from));
253253
},
254254

255-
async load(ref, {requireFn}) {
256-
const [from, to] = rewritePaths.find(([from]) => ref.startsWith(from));
257-
let rewritten = `${to}${ref.slice(from.length)}`;
255+
async load(reference, {requireFn}) {
256+
const [from, to] = rewritePaths.find(([from]) => reference.startsWith(from));
257+
let rewritten = `${to}${reference.slice(from.length)}`;
258258
let useImport = true;
259-
if (ref.endsWith('.cts')) {
259+
if (reference.endsWith('.cts')) {
260260
rewritten = rewritten.replace(/\.cts$/, '.cjs');
261261
useImport = false;
262-
} else if (ref.endsWith('.mts')) {
262+
} else if (reference.endsWith('.mts')) {
263263
rewritten = rewritten.replace(/\.mts$/, '.mjs');
264264
} else {
265265
rewritten = rewritten.replace(testFileExtension, '.js');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"c8": "^8.0.0",
3232
"del": "^7.0.0",
3333
"typescript": "^5.1.3",
34-
"xo": "^0.54.2"
34+
"xo": "^0.58.0"
3535
},
3636
"c8": {
3737
"reporter": [

test/_with-provider.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import {fileURLToPath} from 'node:url';
44
import makeProvider from '@ava/typescript';
55

66
const __dirname = path.dirname(fileURLToPath(import.meta.url));
7-
const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
7+
const package_ = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
88

9-
const createProviderMacro = (identifier, avaVersion, projectDir = __dirname) => (t, run) => run(t, makeProvider({
9+
const createProviderMacro = (identifier, avaVersion, projectDirectory = __dirname) => (t, run) => run(t, makeProvider({
1010
negotiateProtocol(identifiers, {version}) {
1111
t.true(identifiers.includes(identifier));
12-
t.is(version, pkg.version);
12+
t.is(version, package_.version);
1313
return {
1414
ava: {avaVersion},
1515
identifier,
1616
normalizeGlobPatterns: patterns => patterns,
1717
async findFiles({patterns}) {
18-
return patterns.map(file => path.join(projectDir, file));
18+
return patterns.map(file => path.join(projectDirectory, file));
1919
},
20-
projectDir,
20+
projectDir: projectDirectory,
2121
};
2222
},
2323
}));

test/fixtures/install-and-load.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const worker = provider.worker({
1818
...JSON.parse(process.argv[2]),
1919
});
2020

21-
const ref = path.resolve(process.argv[3]);
21+
const reference = path.resolve(process.argv[3]);
2222

23-
if (worker.canLoad(ref)) {
24-
worker.load(ref, {requireFn: createRequire(import.meta.url)});
23+
if (worker.canLoad(reference)) {
24+
worker.load(reference, {requireFn: createRequire(import.meta.url)});
2525
}

test/protocol-ava-6.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import {fileURLToPath} from 'node:url';
44
import test from 'ava';
55
import createProviderMacro from './_with-provider.js';
66

7-
const projectDir = path.dirname(fileURLToPath(import.meta.url));
8-
const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
7+
const projectDirectory = path.dirname(fileURLToPath(import.meta.url));
8+
const package_ = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
99
const withProvider = createProviderMacro('ava-6', '5.3.0');
1010

1111
const validateConfig = (t, provider, config) => {
1212
const error = t.throws(() => provider.main({config}));
13-
error.message = error.message.replace(`v${pkg.version}`, 'v${pkg.version}'); // eslint-disable-line no-template-curly-in-string
13+
error.message = error.message.replace(`v${package_.version}`, 'v${pkg.version}'); // eslint-disable-line no-template-curly-in-string
1414
t.snapshot(error);
1515
};
1616

@@ -77,64 +77,64 @@ test('main() updateGlobs()', withProvider, (t, provider) => {
7777

7878
test('main() interpretChange() without compilation', withProvider, (t, provider) => {
7979
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}});
80-
t.is(main.interpretChange(path.join(projectDir, 'src/foo.ts')), main.changeInterpretations.waitForOutOfBandCompilation);
81-
t.is(main.interpretChange(path.join(projectDir, 'build/foo.js')), main.changeInterpretations.unspecified);
82-
t.is(main.interpretChange(path.join(projectDir, 'src/foo.txt')), main.changeInterpretations.unspecified);
80+
t.is(main.interpretChange(path.join(projectDirectory, 'src/foo.ts')), main.changeInterpretations.waitForOutOfBandCompilation);
81+
t.is(main.interpretChange(path.join(projectDirectory, 'build/foo.js')), main.changeInterpretations.unspecified);
82+
t.is(main.interpretChange(path.join(projectDirectory, 'src/foo.txt')), main.changeInterpretations.unspecified);
8383
});
8484

8585
test('main() interpretChange() with compilation', withProvider, (t, provider) => {
8686
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: 'tsc'}});
87-
t.is(main.interpretChange(path.join(projectDir, 'src/foo.ts')), main.changeInterpretations.unspecified);
88-
t.is(main.interpretChange(path.join(projectDir, 'build/foo.js')), main.changeInterpretations.ignoreCompiled);
89-
t.is(main.interpretChange(path.join(projectDir, 'src/foo.txt')), main.changeInterpretations.unspecified);
87+
t.is(main.interpretChange(path.join(projectDirectory, 'src/foo.ts')), main.changeInterpretations.unspecified);
88+
t.is(main.interpretChange(path.join(projectDirectory, 'build/foo.js')), main.changeInterpretations.ignoreCompiled);
89+
t.is(main.interpretChange(path.join(projectDirectory, 'src/foo.txt')), main.changeInterpretations.unspecified);
9090
});
9191

9292
test('main() resolvePossibleOutOfBandCompilationSources() with compilation', withProvider, (t, provider) => {
9393
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: 'tsc'}});
94-
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDir, 'build/foo.js')), null);
94+
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDirectory, 'build/foo.js')), null);
9595
});
9696

9797
test('main() resolvePossibleOutOfBandCompilationSources() unknown extension', withProvider, (t, provider) => {
9898
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}});
99-
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDir, 'build/foo.bar')), null);
99+
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDirectory, 'build/foo.bar')), null);
100100
});
101101

102102
test('main() resolvePossibleOutOfBandCompilationSources() not a build path', withProvider, (t, provider) => {
103103
const main = provider.main({config: {rewritePaths: {'src/': 'build/'}, compile: false}});
104-
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDir, 'lib/foo.js')), null);
104+
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDirectory, 'lib/foo.js')), null);
105105
});
106106

107107
test('main() resolvePossibleOutOfBandCompilationSources() .cjs but .cts not configured', withProvider, (t, provider) => {
108108
const main = provider.main({config: {extensions: ['ts'], rewritePaths: {'src/': 'build/'}, compile: false}});
109-
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDir, 'build/foo.cjs')), null);
109+
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDirectory, 'build/foo.cjs')), null);
110110
});
111111

112112
test('main() resolvePossibleOutOfBandCompilationSources() .mjs but .mts not configured', withProvider, (t, provider) => {
113113
const main = provider.main({config: {extensions: ['ts'], rewritePaths: {'src/': 'build/'}, compile: false}});
114-
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDir, 'build/foo.mjs')), null);
114+
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDirectory, 'build/foo.mjs')), null);
115115
});
116116

117117
test('main() resolvePossibleOutOfBandCompilationSources() .js but .ts not configured', withProvider, (t, provider) => {
118118
const main = provider.main({config: {extensions: ['cts'], rewritePaths: {'src/': 'build/'}, compile: false}});
119-
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDir, 'build/foo.js')), null);
119+
t.is(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDirectory, 'build/foo.js')), null);
120120
});
121121

122122
test('main() resolvePossibleOutOfBandCompilationSources() .cjs and .cjs and .cts configured', withProvider, (t, provider) => {
123123
const main = provider.main({config: {extensions: ['cjs', 'cts'], rewritePaths: {'src/': 'build/'}, compile: false}});
124-
t.deepEqual(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDir, 'build/foo.cjs')), [path.join(projectDir, 'src/foo.cjs'), path.join(projectDir, 'src/foo.cts')]);
124+
t.deepEqual(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDirectory, 'build/foo.cjs')), [path.join(projectDirectory, 'src/foo.cjs'), path.join(projectDirectory, 'src/foo.cts')]);
125125
});
126126

127127
test('main() resolvePossibleOutOfBandCompilationSources() .mjs and .mjs and .mts configured', withProvider, (t, provider) => {
128128
const main = provider.main({config: {extensions: ['mjs', 'mts'], rewritePaths: {'src/': 'build/'}, compile: false}});
129-
t.deepEqual(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDir, 'build/foo.mjs')), [path.join(projectDir, 'src/foo.mjs'), path.join(projectDir, 'src/foo.mts')]);
129+
t.deepEqual(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDirectory, 'build/foo.mjs')), [path.join(projectDirectory, 'src/foo.mjs'), path.join(projectDirectory, 'src/foo.mts')]);
130130
});
131131

132132
test('main() resolvePossibleOutOfBandCompilationSources() .js and .js, .ts and .tsx configured', withProvider, (t, provider) => {
133133
const main = provider.main({config: {extensions: ['js', 'ts', 'tsx'], rewritePaths: {'src/': 'build/'}, compile: false}});
134-
t.deepEqual(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDir, 'build/foo.js')), [path.join(projectDir, 'src/foo.js'), path.join(projectDir, 'src/foo.ts'), path.join(projectDir, 'src/foo.tsx')]);
134+
t.deepEqual(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDirectory, 'build/foo.js')), [path.join(projectDirectory, 'src/foo.js'), path.join(projectDirectory, 'src/foo.ts'), path.join(projectDirectory, 'src/foo.tsx')]);
135135
});
136136

137137
test('main() resolvePossibleOutOfBandCompilationSources() returns the first possible path that exists', withProvider, (t, provider) => {
138138
const main = provider.main({config: {extensions: ['js', 'ts', 'tsx'], rewritePaths: {'fixtures/load/': 'fixtures/load/compiled/'}, compile: false}});
139-
t.deepEqual(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDir, 'fixtures/load/compiled/index.js')), [path.join(projectDir, 'fixtures/load/index.ts')]);
139+
t.deepEqual(main.resolvePossibleOutOfBandCompilationSources(path.join(projectDirectory, 'fixtures/load/compiled/index.js')), [path.join(projectDirectory, 'fixtures/load/index.ts')]);
140140
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy