Upgrade to ESM
This commit is contained in:
parent
551739c55e
commit
a3b6326377
8 changed files with 48 additions and 33 deletions
14
index.js
14
index.js
|
|
@ -1,9 +1,9 @@
|
|||
'use strict';
|
||||
const path = require('path');
|
||||
const escapeStringRegexp = require('escape-string-regexp');
|
||||
const execa = require('execa');
|
||||
const pkg = require('./package.json');
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import escapeStringRegexp from 'escape-string-regexp';
|
||||
import execa from 'execa';
|
||||
|
||||
const pkg = fs.readFileSync(new URL('package.json', import.meta.url));
|
||||
const help = `See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md`;
|
||||
|
||||
function isPlainObject(x) {
|
||||
|
|
@ -67,7 +67,7 @@ const configProperties = {
|
|||
},
|
||||
};
|
||||
|
||||
module.exports = ({negotiateProtocol}) => {
|
||||
export default function typescriptProvider({negotiateProtocol}) {
|
||||
const protocol = negotiateProtocol(['ava-3.2'], {version: pkg.version});
|
||||
if (protocol === null) {
|
||||
return;
|
||||
|
|
@ -171,4 +171,4 @@ module.exports = ({negotiateProtocol}) => {
|
|||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
13
package.json
13
package.json
|
|
@ -8,6 +8,10 @@
|
|||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"exports": {
|
||||
".": "./index.js"
|
||||
},
|
||||
"type": "module",
|
||||
"author": "Mark Wubben (https://novemberborn.net)",
|
||||
"repository": "avajs/typescript",
|
||||
"license": "MIT",
|
||||
|
|
@ -19,7 +23,7 @@
|
|||
"test": "xo && c8 ava"
|
||||
},
|
||||
"dependencies": {
|
||||
"escape-string-regexp": "^4.0.0",
|
||||
"escape-string-regexp": "^5.0.0",
|
||||
"execa": "^5.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
@ -45,11 +49,6 @@
|
|||
"xo": {
|
||||
"ignores": [
|
||||
"test/broken-fixtures"
|
||||
],
|
||||
"rules": {
|
||||
"import/extensions": "off",
|
||||
"import/order": "off",
|
||||
"unicorn/prefer-module": "off"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
const path = require('path');
|
||||
const pkg = require('../package.json');
|
||||
const makeProvider = require('..');
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import makeProvider from '@ava/typescript';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const pkg = fs.readFileSync(new URL('../package.json', import.meta.url));
|
||||
|
||||
const createProviderMacro = (identifier, avaVersion, projectDir = __dirname) => (t, run) => run(t, makeProvider({
|
||||
negotiateProtocol(identifiers, {version}) {
|
||||
|
|
@ -18,4 +22,4 @@ const createProviderMacro = (identifier, avaVersion, projectDir = __dirname) =>
|
|||
},
|
||||
}));
|
||||
|
||||
module.exports = createProviderMacro;
|
||||
export default createProviderMacro;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const test = require('ava');
|
||||
const makeProvider = require('..');
|
||||
import test from 'ava';
|
||||
import makeProvider from '@ava/typescript';
|
||||
|
||||
test('bails when negotiating protocol returns `null`', t => {
|
||||
const provider = makeProvider({negotiateProtocol: () => null});
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
const path = require('path');
|
||||
const test = require('ava');
|
||||
const del = require('del');
|
||||
const execa = require('execa');
|
||||
const createProviderMacro = require('./_with-provider');
|
||||
import path from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import test from 'ava';
|
||||
import del from 'del';
|
||||
import execa from 'execa';
|
||||
import createProviderMacro from './_with-provider.js';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const withProvider = createProviderMacro('ava-3.2', '3.2.0', path.join(__dirname, 'fixtures'));
|
||||
const withAltProvider = createProviderMacro('ava-3.2', '3.2.0', path.join(__dirname, 'broken-fixtures'));
|
||||
|
||||
|
|
|
|||
12
test/fixtures/install-and-load.js
vendored
12
test/fixtures/install-and-load.js
vendored
|
|
@ -1,6 +1,10 @@
|
|||
const path = require('path');
|
||||
const process = require('process');
|
||||
const makeProvider = require('../..');
|
||||
import {createRequire} from 'node:module';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import makeProvider from '@ava/typescript';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const provider = makeProvider({
|
||||
negotiateProtocol() {
|
||||
|
|
@ -16,5 +20,5 @@ const worker = provider.worker({
|
|||
const ref = path.resolve(process.argv[3]);
|
||||
|
||||
if (worker.canLoad(ref)) {
|
||||
worker.load(ref, {requireFn: require});
|
||||
worker.load(ref, {requireFn: createRequire(import.meta.url)});
|
||||
}
|
||||
|
|
|
|||
3
test/fixtures/typescript/package.json
vendored
Normal file
3
test/fixtures/typescript/package.json
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
const path = require('path');
|
||||
const test = require('ava');
|
||||
const pkg = require('../package.json');
|
||||
const createProviderMacro = require('./_with-provider');
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import test from 'ava';
|
||||
import createProviderMacro from './_with-provider.js';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const pkg = fs.readFileSync(new URL('../package.json', import.meta.url));
|
||||
const withProvider = createProviderMacro('ava-3.2', '3.15.0');
|
||||
|
||||
const validateConfig = (t, provider, config) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue