Skip to content
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

feat(node-resolve): expose plugin version #1050

Merged
merged 1 commit into from Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/node-resolve/src/index.js
Expand Up @@ -5,6 +5,8 @@ import builtinList from 'builtin-modules';
import deepMerge from 'deepmerge';
import isModule from 'is-module';

import { version } from '../package.json';

import { isDirCached, isFileCached, readCachedFile } from './cache';
import { fileExists, readFile, realpath } from './fs';
import resolveImportSpecifiers from './resolveImportSpecifiers';
Expand Down Expand Up @@ -233,6 +235,8 @@ export function nodeResolve(opts = {}) {
return {
name: 'node-resolve',

version,

buildStart(options) {
rollupOptions = options;

Expand Down
13 changes: 9 additions & 4 deletions packages/node-resolve/test/test.js
Expand Up @@ -16,6 +16,11 @@ const failOnWarn = (t) => (warning) =>

const getLastPathFragment = (path) => path && path.split(/[\\/]/).slice(-1)[0];

test('exposes plugin version', (t) => {
const plugin = nodeResolve();
t.regex(plugin.version, /^\d+\.\d+\.\d+/);
});

test('finds a module with jsnext:main', async (t) => {
const bundle = await rollup({
input: 'jsnext.js',
Expand Down Expand Up @@ -487,13 +492,13 @@ test('passes on "isEntry" flag', async (t) => {
]
});
t.deepEqual(resolveOptions, [
['other.js', 'main.js', { custom: void 0, isEntry: true }],
['main.js', void 0, { custom: void 0, isEntry: true }],
['dep.js', 'main.js', { custom: void 0, isEntry: false }]
['other.js', 'main.js', { custom: {}, isEntry: true }],
['main.js', void 0, { custom: {}, isEntry: true }],
['dep.js', 'main.js', { custom: {}, isEntry: false }]
]);
});

test.only('passes on custom options', async (t) => {
test('passes on custom options', async (t) => {
const resolveOptions = [];
await rollup({
input: 'entry/other.js',
Expand Down