Import package.json
This commit is contained in:
parent
2e82538b6e
commit
46c795c1b5
3 changed files with 7 additions and 9 deletions
6
index.js
6
index.js
|
|
@ -3,9 +3,9 @@ import path from 'node:path';
|
|||
import {pathToFileURL} from 'node:url';
|
||||
import escapeStringRegexp from 'escape-string-regexp';
|
||||
import {execa} from 'execa';
|
||||
import pkg from './package.json' with {type: 'json'};
|
||||
|
||||
const package_ = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url)));
|
||||
const help = `See https://github.com/avajs/typescript/blob/v${package_.version}/README.md`;
|
||||
const help = `See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md`;
|
||||
|
||||
function isPlainObject(x) {
|
||||
return x !== null && typeof x === 'object' && Reflect.getPrototypeOf(x) === Object.prototype;
|
||||
|
|
@ -75,7 +75,7 @@ const changeInterpretations = Object.freeze(Object.assign(Object.create(null), {
|
|||
}));
|
||||
|
||||
export default function typescriptProvider({negotiateProtocol}) {
|
||||
const protocol = negotiateProtocol(['ava-6'], {version: package_.version});
|
||||
const protocol = negotiateProtocol(['ava-6', 'ava-8'], {version: pkg.version});
|
||||
if (protocol === null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import pkg from '../package.json' with {type: 'json'};
|
||||
import makeProvider from '@ava/typescript';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const package_ = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
|
||||
|
||||
const createProviderMacro = (identifier, avaVersion, projectDirectory = __dirname) => (t, run) => run(t, makeProvider({
|
||||
negotiateProtocol(identifiers, {version}) {
|
||||
t.true(identifiers.includes(identifier));
|
||||
t.is(version, package_.version);
|
||||
t.is(version, pkg.version);
|
||||
return {
|
||||
ava: {avaVersion},
|
||||
identifier,
|
||||
|
|
|
|||
|
|
@ -1,16 +1,15 @@
|
|||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import test from 'ava';
|
||||
import pkg from '../package.json' with {type: 'json'};
|
||||
import createProviderMacro from './_with-provider.js';
|
||||
|
||||
const projectDirectory = path.dirname(fileURLToPath(import.meta.url));
|
||||
const package_ = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
|
||||
const withProvider = createProviderMacro('ava-6', '5.3.0');
|
||||
|
||||
const validateConfig = (t, provider, config) => {
|
||||
const error = t.throws(() => provider.main({config}));
|
||||
error.message = error.message.replace(`v${package_.version}`, 'v${pkg.version}'); // eslint-disable-line no-template-curly-in-string
|
||||
error.message = error.message.replace(`v${pkg.version}`, 'v${pkg.version}'); // eslint-disable-line no-template-curly-in-string
|
||||
t.snapshot(error);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue