Skip to content

Commit

Permalink
Use correct require instance and enable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 20, 2022
1 parent 44fbb21 commit b08c3a6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cli/run/commandPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from 'path';
import { pathToFileURL } from 'url';
import type { InputOptions } from '../../src/rollup/types';
import { stdinPlugin } from './stdin';
import { waitForInputPlugin } from './waitForInput';
Expand Down Expand Up @@ -73,7 +74,9 @@ async function loadAndRegisterPlugin(
try {
if (pluginText[0] == '.') pluginText = resolve(pluginText);
// Windows absolute paths must be specified as file:// protocol URL
else if (pluginText.match(/^[A-Za-z]:\\/)) pluginText = "file://" + require$$0.resolve(pluginText);
else if (pluginText.match(/^[A-Za-z]:\\/)) {
pluginText = pathToFileURL(resolve(pluginText)).href;
}
plugin = await requireOrImport(pluginText);
} catch (err: any) {
throw new Error(`Cannot load plugin "${pluginText}": ${err.message}.`);
Expand Down
5 changes: 3 additions & 2 deletions test/cli/samples/plugin/absolute-esm/_config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { sep } = require('path');

module.exports = {
description: 'ESM CLI --plugin /absolute/path',
minNodeVersion: 12,
skipIfWindows: true,
command: `echo 'console.log(1 ? 2 : 3);' | rollup -p "\`pwd\`/my-esm-plugin.mjs={comment: 'Absolute ESM'}"`
command: `rollup main.js -p "${__dirname}${sep}my-esm-plugin.mjs={comment: 'Absolute ESM'}"`
};
1 change: 1 addition & 0 deletions test/cli/samples/plugin/absolute-esm/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(1 ? 2 : 3);
6 changes: 4 additions & 2 deletions test/cli/samples/plugin/absolute/_config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { sep } = require('path');

module.exports = {
description: 'CLI --plugin /absolute/path',
skipIfWindows: true,
command: `echo 'console.log(VALUE);' | rollup -p "\`pwd\`/my-plugin={VALUE: 'absolute', ZZZ: 1}"`
minNodeVersion: 12,
command: `rollup main.js -p "${__dirname}${sep}my-plugin.js={VALUE: 'absolute', ZZZ: 1}"`
};
1 change: 1 addition & 0 deletions test/cli/samples/plugin/absolute/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(VALUE);

0 comments on commit b08c3a6

Please sign in to comment.