Skip to content

Commit f958b18

Browse files
committed
Upgrade to ESM
1 parent 5560c25 commit f958b18

File tree

8 files changed

+50
-35
lines changed

8 files changed

+50
-35
lines changed

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
'use strict';
2-
const path = require('path');
3-
const escapeStringRegexp = require('escape-string-regexp');
4-
const execa = require('execa');
5-
const pkg = require('./package.json');
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import escapeStringRegexp from 'escape-string-regexp';
4+
import execa from 'execa';
65

6+
const pkg = fs.readFileSync(new URL('package.json', import.meta.url));
77
const help = `See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md`;
88

99
function isPlainObject(x) {
@@ -67,7 +67,7 @@ const configProperties = {
6767
},
6868
};
6969

70-
module.exports = ({negotiateProtocol}) => {
70+
export default function typescriptProvider({negotiateProtocol}) {
7171
const protocol = negotiateProtocol(['ava-3.2'], {version: pkg.version});
7272
if (protocol === null) {
7373
return;
@@ -171,4 +171,4 @@ module.exports = ({negotiateProtocol}) => {
171171
};
172172
},
173173
};
174-
};
174+
}

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"files": [
99
"index.js"
1010
],
11+
"exports": {
12+
".": "./index.js"
13+
},
14+
"type": "module",
1115
"author": "Mark Wubben (https://novemberborn.net)",
1216
"repository": "avajs/typescript",
1317
"license": "MIT",
@@ -19,7 +23,7 @@
1923
"test": "xo && c8 ava"
2024
},
2125
"dependencies": {
22-
"escape-string-regexp": "^4.0.0",
26+
"escape-string-regexp": "^5.0.0",
2327
"execa": "^5.1.1"
2428
},
2529
"devDependencies": {
@@ -45,11 +49,6 @@
4549
"xo": {
4650
"ignores": [
4751
"test/broken-fixtures"
48-
],
49-
"rules": {
50-
"import/extensions": "off",
51-
"import/order": "off",
52-
"unicorn/prefer-module": "off"
53-
}
52+
]
5453
}
5554
}

test/_with-provider.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
const path = require('path');
2-
const pkg = require('../package.json');
3-
const makeProvider = require('..');
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import {fileURLToPath} from 'node:url';
4+
import makeProvider from '@ava/typescript';
5+
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
7+
const pkg = fs.readFileSync(new URL('../package.json', import.meta.url));
48

59
const createProviderMacro = (identifier, avaVersion, projectDir = __dirname) => (t, run) => run(t, makeProvider({
610
negotiateProtocol(identifiers, {version}) {
@@ -18,4 +22,4 @@ const createProviderMacro = (identifier, avaVersion, projectDir = __dirname) =>
1822
},
1923
}));
2024

21-
module.exports = createProviderMacro;
25+
export default createProviderMacro;

test/base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const test = require('ava');
2-
const makeProvider = require('..');
1+
import test from 'ava';
2+
import makeProvider from '@ava/typescript';
33

44
test('bails when negotiating protocol returns `null`', t => {
55
const provider = makeProvider({negotiateProtocol: () => null});

test/compilation.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
const path = require('path');
2-
const test = require('ava');
3-
const del = require('del');
4-
const execa = require('execa');
5-
const createProviderMacro = require('./_with-provider');
6-
1+
import path from 'node:path';
2+
import {fileURLToPath} from 'node:url';
3+
import test from 'ava';
4+
import del from 'del';
5+
import execa from 'execa';
6+
import createProviderMacro from './_with-provider.js';
7+
8+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
79
const withProvider = createProviderMacro('ava-3.2', '3.2.0', path.join(__dirname, 'fixtures'));
810
const withAltProvider = createProviderMacro('ava-3.2', '3.2.0', path.join(__dirname, 'broken-fixtures'));
911

test/fixtures/install-and-load.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
const path = require('path');
2-
const process = require('process');
3-
const makeProvider = require('../..');
1+
import {createRequire} from 'node:module';
2+
import path from 'node:path';
3+
import process from 'node:process';
4+
import {fileURLToPath} from 'node:url';
5+
import makeProvider from '@ava/typescript';
6+
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
48

59
const provider = makeProvider({
610
negotiateProtocol() {
@@ -16,5 +20,5 @@ const worker = provider.worker({
1620
const ref = path.resolve(process.argv[3]);
1721

1822
if (worker.canLoad(ref)) {
19-
worker.load(ref, {requireFn: require});
23+
worker.load(ref, {requireFn: createRequire(import.meta.url)});
2024
}

test/fixtures/typescript/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

test/protocol-ava-3.2.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
const path = require('path');
2-
const test = require('ava');
3-
const pkg = require('../package.json');
4-
const createProviderMacro = require('./_with-provider');
5-
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import {fileURLToPath} from 'node:url';
4+
import test from 'ava';
5+
import createProviderMacro from './_with-provider.js';
6+
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
const pkg = fs.readFileSync(new URL('../package.json', import.meta.url));
69
const withProvider = createProviderMacro('ava-3.2', '3.15.0');
710

811
const validateConfig = (t, provider, config) => {

0 commit comments

Comments
 (0)