8000 Updates and ESM support by novemberborn · Pull Request #36 · avajs/typescript · GitHub
[go: up one dir, main page]

Skip to content

Updates and ESM support #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Upgrade to ESM
  • Loading branch information
novemberborn committed Nov 1, 2021
commit f958b1878f124358746fb2955126d4d4cdc076ff
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -171,4 +171,4 @@ module.exports = ({negotiateProtocol}) => {
};
},
};
};
}
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"files": [
"index.js"
],
"exports": {
".": "./index.js"
},
"type": "module",
"author": "Mark Wubben (https://novemberborn.net)",
"repository": "avajs/typescript",
"license": "MIT",
Expand All @@ -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": {
Expand All @@ -45,11 +49,6 @@
"xo": {
"ignores": [
"test/broken-fixtures"
],
"rules": {
"import/extensions": "off",
"import/order": "off",
"unicorn/prefer-module": "off"
}
]
}
}
12 changes: 8 additions & 4 deletions test/_with-provider.js
Original file line number Diff line number Diff line change
@@ -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}) {
Expand All @@ -18,4 +22,4 @@ const createProviderMacro = (identifier, avaVersion, projectDir = __dirname) =>
},
}));

module.exports = createProviderMacro;
export default createProviderMacro;
4 changes: 2 additions & 2 deletions test/base.js
Original file line number Diff line number Diff line change
@@ -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});
Expand Down
14 changes: 8 additions & 6 deletions test/compilation.js
Original file line number Diff line number Diff line change
@@ -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'));

Expand Down
12 changes: 8 additions & 4 deletions test/fixtures/install-and-load.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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 changes: 3 additions & 0 deletions test/fixtures/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
13 changes: 8 additions & 5 deletions test/protocol-ava-3.2.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
0